You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "void-ptr974 (via GitHub)" <gi...@apache.org> on 2026/06/18 06:51:51 UTC

[PR] [improve][broker] Avoid stream allocation when summing dispatch bytes [pulsar]

void-ptr974 opened a new pull request, #26055:
URL: https://github.com/apache/pulsar/pull/26055

   ### 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
   
   JMH data gathered locally before this PR, using `DispatcherDispatchPathBenchmark.(streamTotalBytes|loopTotalBytes)` with `entriesCount=1000`, `-wi 1 -i 3 -w 1s -r 1s -f 1 -prof gc`:
   
   | Benchmark | Score | Allocation |
   | --- | ---: | ---: |
   | streamTotalBytes | ~878 ns/op | ~256 B/op |
   | loopTotalBytes | ~825 ns/op | ~0 B/op |
   
   ### Verification
   
   - `./gradlew :pulsar-broker:compileJava :pulsar-broker:checkstyleMain --max-workers=1`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][broker] Improve dispatch performance by summing entry bytes with a loop [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari merged PR #26055:
URL: https://github.com/apache/pulsar/pull/26055


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][broker] Improve dispatch performance by summing entry bytes with a loop [pulsar]

Posted by "void-ptr974 (via GitHub)" <gi...@apache.org>.
void-ptr974 commented on code in PR #26055:
URL: https://github.com/apache/pulsar/pull/26055#discussion_r3440157864


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java:
##########
@@ -745,6 +745,14 @@ private synchronized void handleSendingMessagesAndReadingMore(ReadType readType,
         }
     }
 
+    static long getTotalBytesSize(List<Entry> entries) {

Review Comment:
   Thanks, done. Moved the helper to `AbstractPersistentDispatcherMultipleConsumers` and both dispatchers now reuse it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][broker] Improve dispatch performance by summing entry bytes with a loop [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on code in PR #26055:
URL: https://github.com/apache/pulsar/pull/26055#discussion_r3438137952


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java:
##########
@@ -745,6 +745,14 @@ private synchronized void handleSendingMessagesAndReadingMore(ReadType readType,
         }
     }
 
+    static long getTotalBytesSize(List<Entry> entries) {

Review Comment:
   Instead of duplicating the code, we should move to a shared place



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org