[improve][broker] Improve dispatch performance by summing entry bytes with a loop#26055
Open
void-ptr974 wants to merge 1 commit into
Open
[improve][broker] Improve dispatch performance by summing entry bytes with a loop#26055void-ptr974 wants to merge 1 commit into
void-ptr974 wants to merge 1 commit into
Conversation
e540c3c to
68c04be
Compare
merlimat
reviewed
Jun 18, 2026
| } | ||
| } | ||
|
|
||
| static long getTotalBytesSize(List<Entry> entries) { |
Contributor
There was a problem hiding this comment.
Instead of duplicating the code, we should move to a shared place
Contributor
Author
There was a problem hiding this comment.
Thanks, done. Moved the helper to AbstractPersistentDispatcherMultipleConsumers and both dispatchers now reuse it.
68c04be to
cf896a3
Compare
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
The shared-subscription dispatch path sums entry bytes for every read batch. The existing implementation uses a stream pipeline, which adds avoidable allocation and dispatch overhead on this hot path.
Modifications
Replace the stream-based byte summation in both multiple-consumer dispatchers with a simple indexed loop.
Performance
This improves the dispatch hot path by reducing per-read-batch CPU work and eliminating stream pipeline allocation.
JMH data gathered locally using
DispatcherDispatchPathBenchmark.(streamTotalBytes|loopTotalBytes), with-p entriesCount=32,256,1000 -wi 2 -i 5 -w 1s -r 1s -f 1 -bm avgt -tu ns -prof gc:Verification
PersistentDispatcherTotalBytesTestcoverage for empty, single-entry, and large 1024-entry batches with varying realEntryImplpayload sizes../gradlew :pulsar-broker:compileJava :pulsar-broker:checkstyleMain --max-workers=1./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.persistent.PersistentDispatcherTotalBytesTest --max-workers=1 -PtestRetryCount=0./gradlew :pulsar-broker:checkstyleTest --max-workers=1