Use batch-draining queues in SingleThreadExecutor#4836
Open
merlimat wants to merge 2 commits into
Open
Conversation
void-ptr974
reviewed
Jul 11, 2026
|
|
||
| @SuppressWarnings("unchecked") | ||
| public GrowableBatchedArrayBlockingQueue(int initialCapacity) { | ||
| data = (T[]) new Object[initialCapacity]; |
Contributor
There was a problem hiding this comment.
Maybe we need check initialcapacity non-negative here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
SingleThreadExecutorbacks everyOrderedExecutorthread — including the bookie read/write thread pools — so its queue is on the task-dispatch hot path. Today it uses:GrowableMpScArrayConsumerBlockingQueue(unbounded, the default), draining element-by-element viadrainTo(ArrayList)ArrayBlockingQueue(bounded, whenmaxTasksInQueueis set)Meanwhile
BatchedArrayBlockingQueue— purpose-built in the same package for the many-producers/one-consumer shape, withSystem.arraycopybatch draining — was unused by the executor. A JMH comparison (8 producers, consumers running the executor's exact drain loops) showed the growable queue is actually the slowest option, and the batched queue the fastest:GrowableMpScArrayConsumerBlockingQueue(current unbounded)ArrayBlockingQueue(current bounded)GrowableBatchedArrayBlockingQueue(new, unbounded)BatchedArrayBlockingQueue(bounded)Changes
GrowableBatchedArrayBlockingQueue: the unbounded companion ofBatchedArrayBlockingQueue. Same single-lock design and two-spanSystem.arraycopybatch operations (takeAll/pollAll/putAll), but with nonotFullcondition — producers never block; the backing array doubles when full (and never shrinks), like the queue it replaces.SingleThreadExecutornow usesBatchedArrayBlockingQueuefor the bounded case and the new growable queue for the unbounded case, and the run loop drains withtakeAllinto a reusableRunnable[](capped at 1024) instead of per-elementdrainTo(ArrayList).GrowableMpScArrayConsumerBlockingQueue(and its test): the executor was its only production user, so it is fully superseded by the new queue. The stray usage inBatchedArrayBlockingQueueTest.blockingTakenow testsBatchedArrayBlockingQueueitself, as intended.SingleThreadExecutorQueueBenchmark) comparing the queue options with executor-style consumers.Verified: new queue test (9/9),
BatchedArrayBlockingQueueTest,TestSingleThreadExecutor(10/10),TestOrderedExecutor,TestOrderedExecutorDecorators, plusBookieJournalTestas an integration smoke through the bookie path (16/16). Checkstyle clean.