Github user chinmaykolhatkar commented on a diff in the pull request:

    
https://github.com/apache/incubator-apex-malhar/pull/157#discussion_r49928222
  
    --- Diff: 
library/src/main/java/com/datatorrent/lib/async/AbstractAsyncProcessor.java ---
    @@ -0,0 +1,344 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package com.datatorrent.lib.async;
    +
    +import java.util.Iterator;
    +import java.util.Queue;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +import java.util.concurrent.Future;
    +import javax.validation.constraints.Min;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.google.common.collect.Lists;
    +
    +import com.datatorrent.api.Context;
    +import com.datatorrent.api.Operator.IdleTimeHandler;
    +import com.datatorrent.common.util.BaseOperator;
    +
    +
    +/**
    + * This base operator can be used to enqueue tuples for asynchronous and 
parallel processing by separate worker threads.
    + *
    + * User can configure number of threads required for async processing. By 
default
    + * threads will be created on need basis with no upper limit. These worker 
threads, spawned by operator thread,
    + * can also be configured to processing timeout.
    + *
    + * <b>Workflow is as follows:</b>
    + * <ol>
    + *   <li>Implementing class can enqueue the tuples of type QUEUETUPLE 
using <i>enqueueTupleForProcessing</i>
    + *       method.</li>
    + *   <li>When a tuple gets its turn for execution, 
<i>processTupleAsync</i> gets called
    + *       by worker thread. This is asynchronous call</li>
    + *   <li>Based on maintainTupleOrder parameter, the results are 
consolidated at the end of every window and respective
    + *       call to <i>handleProcessedTuple</i> will be made. This callback 
is in operator thread.</li>
    + * </ol>
    + *
    + *
    + * <b>Use case examples:</b>
    + * <ul>
    + *   <li>Parallel reads from external datastore/database system.</li>
    + *   <li>Operations which are long running tasks per tuple but DAG i/o 
should not be blocked.</li>
    + * </ul>
    + *
    + * @param <QUEUETUPLE> input type of tuple
    + * @param <RESULTTUPLE> Result of async processing of tuple.
    + */
    +public abstract class AbstractAsyncProcessor<QUEUETUPLE, RESULTTUPLE> 
extends BaseOperator implements IdleTimeHandler
    +{
    +  private static final Logger logger = 
LoggerFactory.getLogger(AbstractAsyncProcessor.class);
    +
    +  /**
    +   * This is an executor service which holds thread pool and enqueues task 
for processing.
    +   */
    +  private transient ExecutorService executor;
    +
    +  /**
    +   * Number of worker threads for processing
    +   * 0   - Threads will be created as per need.
    --- End diff --
    
    I agree.What would you suggest a good ma number will be. I'll remove the 
cached pool all together.
    And put a limit on that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to