optimize StreamUtil and fix the LimitingExecutor #550
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(1) #548 fixed the issue to execute mapper function to each batch in the thread-pool. but the batches are still executed sequentially. We need to fix the issues to have the batches executed in parallel. Here we implement a Collector:
- the accumulate method collect data from original stream, create batches, and submit jobs for executing each batch to thread-pool.
- the finisher method handles the last batch, submit the job for the last batch to thread-pool. It also connect the result for the jobs executed in the thread-pool, combine the results, and stream the results.
Tested this can execute the batches in the thread-pool in parallel.
(2) Fix LimitingExecutor. LimitingExecutor use a Semaphore to control the maximum number of jobs concurrently executed in the thread-pool. But the Semaphore is just used to guard the ThreadPool.execute(command), and the ThreadPool.execute just submit the job to the threadpool. So the Semaphore does not guard the number of jobs concurrently running in the pool. We fix this issue by:
a. require a Semaphore when submitting a new job;
b. release a Semaphore when a job completes;