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 11:57:11 UTC

[PR] [improve][broker] Avoid clearing absent dispatch ack sets [pulsar]

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

   ### Motivation
   
   `AbstractBaseDispatcher#filterEntriesForConsumer` writes `null` into `EntryBatchIndexesAcks` for every entry that has no deleted batch indexes. `EntryBatchIndexesAcks` instances are already cleared when recycled, so repeatedly writing the same `null` value adds avoidable work on dispatch batches where most entries have no ack set.
   
   ### Modifications
   
   Avoid calling `EntryBatchIndexesAcks#setIndexesAcks(i, null)` when the cursor returns no ack set for an entry.
   
   ### Performance
   
   JMH data gathered locally before this PR, using `DispatcherDispatchPathBenchmark.(clearNullAckSets|skipNullAckSets)`, `-wi 1 -i 3 -w 1s -r 1s -f 1 -prof gc`:
   
   | entriesCount | clearNullAckSets | skipNullAckSets |
   | ---: | ---: | ---: |
   | 256 | ~586 ns/op | ~326 ns/op |
   | 1000 | ~2161 ns/op | ~1221 ns/op |
   
   ### Verification
   
   - Added `AbstractBaseDispatcherTest` coverage for a 512-entry dispatch batch with varying payload sizes and batch sizes, where the cursor returns a null ack set for every entry.
   - `./gradlew :pulsar-broker:compileJava :pulsar-broker:checkstyleMain --max-workers=1`
   - `./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.AbstractBaseDispatcherTest --tests org.apache.pulsar.broker.service.EntryBatchIndexesAcksTest --max-workers=1 -PtestRetryCount=0`
   - `./gradlew :pulsar-broker:checkstyleTest --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 skipping redundant null ack-set writes [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26057:
URL: https://github.com/apache/pulsar/pull/26057#issuecomment-4757057687

   @void-ptr974 Please [join Pulsar slack #dev channel ](https://pulsar.apache.org/community/#section-discussions)for coordinating the efforts. For eventually gaining official committer status, you cannot remain completely anonymous since major contributors need to sign [the Apache ICLA](https://www.apache.org/licenses/icla.pdf) with their legal name. The ICLA could be requested even before official committer status.
   
   https://www.apache.org/licenses/contributor-agreements.html:
   > While small contributions to Apache projects are made under clause 5 of the Apache-2.0 license, all project maintainers of, as well as contributors of any large contributions to, any Apache projects must complete, sign, and submit via email an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) (ICLA).


-- 
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 skipping redundant null ack-set writes [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26057:
URL: https://github.com/apache/pulsar/pull/26057#issuecomment-4750688501

   > This improves dispatch performance in common no-ackSet batches by avoiding a redundant write for each entry with no deleted batch indexes.
   > 
   > JMH data gathered locally using `DispatcherDispatchPathBenchmark.(clearNullAckSets|skipNullAckSets)`, with `-p entriesCount=256,1000 -wi 5 -i 7 -w 1s -r 1s -f 1 -bm avgt -tu ns -prof gc`:
   > 
   > entriesCount	clearNullAckSets	skipNullAckSets	improvement
   > 256	1327.7 ns/op	512.9 ns/op	61.4%
   > 1000	5004.1 ns/op	1540.6 ns/op	69.2%
   
   The code that is avoid is this call:
   
   ```java
       public void setIndexesAcks(int entryIdx, Pair<Integer, long[]> indexesAcks) {
           this.indexesAcks[entryIdx] = indexesAcks;
       }
   ```
   
   It is surprising if the benchmark shows any significant difference. Comparing an array operation to a no-op is not a very useful benchmark. Just wondering about the true motivation of such changes. For performance optimizations, it will be more useful to put the main focus on actual bottlenecks which exist in Pulsar. There's always a bottleneck that can be improved. This single change isn't a problem, but the problem is that every single PR has a cost in reviewing besides creating the PR. A performance optimization strategy based on bottleneck analysis will be more impactful for production use cases.
   One way to find bottlenecks is shown in branch-4.2 test https://github.com/apache/pulsar/blob/branch-4.2/tests/integration/src/test/java/org/apache/pulsar/tests/integration/profiling/PulsarProfilingTest.java. It's currently usable only in branch-4.2 since the required build system parts haven't been migrated from maven to gradle.
   An unsolved bottleneck is the crc32 checksum handling in Pulsar client. There must be ways to improve that.
   On the broker side, there's also config related bottlenecks where resources are not fully and that limits throughput (`dispatcherMaxReadBatchSize` for example).
   
   


-- 
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 skipping redundant null ack-set writes [pulsar]

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

   @lhotari Sorry for the late reply, and thank you very much for taking the time to write such detailed guidance.
   
   The benchmark was run on my local MacBook Pro, which is an Intel-based 2020 model with a 2.0GHz quad-core 10th-generation Intel Core i5. I understand that this should only be treated as local microbenchmark data, not as evidence of an end-to-end broker throughput improvement. If I do more performance testing later, I’ll try to use a Linux x86-64 environment and provide more benchmark/profiling data.
   
   I’ve already signed and submitted the Apache ICLA, and my preferred Apache ID is `voidptr974`. I’ve also joined the Pulsar Slack, so I’ll use the `#dev` channel to coordinate related work when needed.
   
   Thanks also for sharing the benchmarking/profiling reference. It is very helpful for me to better understand how to approach performance-related changes in the community. I’ll keep the suggested workflow in mind, especially starting from real workload profiling, using representative benchmarks, and sharing enough details for review.
   
   I’ll also keep an eye on the other points you mentioned, including the client-side crc32 calculation and the Gradle profiling tooling.
   
   Thanks again for the guidance and patience. I’m still learning how to contribute more effectively in the Pulsar community, and I hope to continue making useful contributions to the project over time.
   


-- 
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 skipping redundant null ack-set writes [pulsar]

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

   @lhotari Thanks for the feedback. I agree that the original benchmark was too narrow:
   it mostly measured the isolated cost of writing null into EntryBatchIndexesAcks,
   so it should not be used to claim end-to-end dispatch throughput improvement.
   
   I added both the original benchmark and a more realistic one here:
   
   https://gist.github.com/void-ptr974/dc08991a1d8a349ffb6868a10e83889f
   
   The real-path benchmark calls AbstractBaseDispatcher#filterEntriesForConsumer
   with real entries, batch metadata, EntryBatchSizes, EntryBatchIndexesAcks, and a
   cursor returning no deleted batch indexes. The measured local improvement is
   smaller: ~11.9% for 256 entries, ~5.7% for 1000 entries, and small/inconclusive
   for 5000 entries.
   
   That said, I still think the code change is valid. The old code writes null into
   EntryBatchIndexesAcks for every entry without an ack set, while the structure is
   already cleared before reuse. Skipping that redundant write removes unnecessary
   work from a dispatch hot-path loop without changing behavior.
   
   I understand the concern about review bandwidth. I also try to help from the
   contributor side by reviewing Pulsar PRs when I can. GitHub search currently
   shows that I have reviewed 47 PRs in apache/pulsar, which I think is a
   meaningful amount of review work from a contributor. I am trying to contribute
   on both sides: submitting focused patches and helping review other pending PRs.
   
   If it would be helpful, I can also include the JMH benchmark file in future
   performance-related PRs, or attach it to the PR when the benchmark is only meant
   for validation and not for long-term maintenance.
   
   As a relatively new contributor, I am trying to understand what kind of help is
   most useful for the Pulsar community. Should I focus more on reviewing pending
   PRs, investigating known performance bottlenecks with profiling data, fixing
   flaky tests, helping with Gradle migration, or something else?


-- 
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 skipping redundant null ack-set writes [pulsar]

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

   @lhotari That’s a good point. I didn’t realize before how much the benchmark/profiling environment could matter, especially between macOS and Linux x86-64.
   
   For future performance-related changes, I’ll try to test on a Linux x86-64 machine rather than relying on local macOS results.


-- 
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 skipping redundant null ack-set writes [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26057:
URL: https://github.com/apache/pulsar/pull/26057#issuecomment-4758356981

   Good article: [Wicked-Fast on the JVM: The Two Costs That Actually Matter](https://www.linkedin.com/pulse/wicked-fast-jvm-two-costs-actually-matter-john-de-goes-d459c)


-- 
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 skipping redundant null ack-set writes [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26057:
URL: https://github.com/apache/pulsar/pull/26057#issuecomment-4766443940

   > The benchmark was run on my local Intel-based 2020 MacBook Pro with a 2.0GHz quad-core 10th-generation Core i5, so I agree it should only be considered local microbenchmark data. If I do more performance testing later, I’ll try to use a Linux x86-64 environment and provide more benchmark/profiling details.
   
   When profiling on MacOS, there's at least one limitation with AsyncProfiler ["CPU sampling engines"](https://github.com/async-profiler/async-profiler/blob/master/docs/CpuSamplingEngines.md). On MacOS `itimer` is the only available option for sampling cpu. It's has certain limitations and on MacOS it's not accurate
   "itimer profiles may be even less accurate on macOS, where itimer signals are often biased towards system calls."
   
   One problem in benchmarking with MacOS is that `System.nanoTime()` is slower compared to Linux. This can be seen in https://github.com/apache/pulsar/blob/master/microbench/src/main/java/org/apache/pulsar/broker/qos/DefaultMonotonicClockBenchmark.java. There used to be a mitigation with [DefaultMonotonicSnapshotClock](https://github.com/apache/pulsar/blob/626b211f91fd8d1e9821ae8e2b9b29520e72ac63/pulsar-broker/src/main/java/org/apache/pulsar/broker/qos/DefaultMonotonicSnapshotClock.java), but that was removed since it caused more problems than it solved.
   `System.nanoTime()` performance matters mainly in Pulsar code base for `AsyncTokenBucket` performance.
   
   [os::javaTimeNanos for MacOS in JDK 25](https://github.com/openjdk/jdk25u/blob/78205f82e99847e9864194f381eb37e1411a3bf7/src/hotspot/os/bsd/os_bsd.cpp#L809-L831)
   
   [os::javaTimeNanos for Posix (Linux) in JDK 25](https://github.com/openjdk/jdk25u/blob/78205f82e99847e9864194f381eb37e1411a3bf7/src/hotspot/os/posix/os_posix.cpp#L1509-L1515)
   
   Slightly outdated [blog post about timekeeping in Java](https://serce.me/posts/2019-05-16-the-matter-of-time).
   
   Profiling in a docker container on MacOS addresses some problems, but it might provide skewed results compared to providing directly on Linux x86-64 hardware (or profiling on Apple Silicon compared to Linux on aarch64). For Pulsar, we have been optimizing for x86-64 by now. That might change in that future so that profiling and optimization is also targeting aarch64.


-- 
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 skipping redundant null ack-set writes [pulsar]

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


-- 
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 skipping redundant null ack-set writes [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #26057:
URL: https://github.com/apache/pulsar/pull/26057#issuecomment-4754875736

   > I added the original benchmark, a real-path benchmark, and the results here:
   > 
   > https://gist.github.com/void-ptr974/dc08991a1d8a349ffb6868a10e83889f
   > 
   > The real-path benchmark calls `AbstractBaseDispatcher#filterEntriesForConsumer` with real entries, batch metadata, `EntryBatchSizes`, `EntryBatchIndexesAcks`, and a cursor returning no deleted batch indexes.
   > 
   > entriesCount	before	after	improvement
   > 256	1474.017 ns/op	1298.001 ns/op	11.94%
   > 1000	6121.259 ns/op	5774.128 ns/op	5.67%
   > 5000	42488.158 ns/op	41644.948 ns/op	1.98%
   > The 5000-entry result has overlapping confidence intervals, so I would treat it as small/inconclusive. Allocation is effectively unchanged.
   
   Thanks! Just curious to known which hardware did you test with?
   
   > So I agree the impact should be described as a small local improvement in the `filterEntriesForConsumer` no-ackSet path, not as an end-to-end throughput improvement. For future performance work, I will focus more on real-path benchmarks and profiling-backed bottleneck analysis. If helpful, I can also include or attach the JMH benchmark source in performance-related PRs.
   
   Yes, adding JMH benchmark source will be useful for optimizations. 
   Regarding future performance work, there would be a lot of low hanging fruit since there hasn't been a lot of focus recently in getting rid of the major bottlenecks. It would be great if you could check how to optimize the crc32 calculation which is a bottleneck for client performance, IIRC. Contributing the performance optimization tooling to the new Gradle build ([PulsarProfilingTest maven build solution](https://github.com/apache/pulsar/blob/2baa1f7e67a4091b01c558048bb75b2667f2dfa5/pom.xml#L3077-L3129)) will also be useful so that it's possible to find the bottlenecks. AsyncProfiler contains also `jfrsync` option which uses JFR for all other features expect for profing information that AsyncProfiler can provide more accurately and efficiently. AI tooling such as https://github.com/btraceio/jafar could possibly be used also used for analysing AsyncProfiler profiles stored in JFR format using [jfr_flamegraph](https://github.com/btraceio/jafar/blob/main/doc/mcp/Tutorial.md#jfr_fla
 megraph) JFR MCP tool.
   For profiling, I'd recommend Linux on x86-64. The results could be very different on arm64 on MacOS. 
   


-- 
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