GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [improve][misc] Use Netty's adaptive allocator for Pulsar's default allocator by lhotari · Pull Request #26720 · apache/pulsar Conversation
|
| Setting | Key_Shared 500×20 | IoT telemetry high rate |
|---|---|---|
| Cluster | 1 broker, 3 bookies | 1 broker, 3 bookies |
| Ledger replication | E=1, W=1, A=1 | broker defaults |
| Producers | 500 gateways × 1 topic | 500 gateways × 1 topic |
| Applications | 1 × 20 consumers, Key_Shared | 5 × 10 consumers, Key_Shared |
| Messages | 4,000,000 measured, 1,000,000 warmup | 5,000,000 measured, 1,000,000 warmup |
| Payload | 128 bytes, batching off | 64 bytes, batching on |
| Rate limit | none | none |
Every run delivered all messages to every application with no duplicates, no ordering violations and no invalid messages.
Key_Shared 500×20, unprofiled:
| Without | With | Change | |
|---|---|---|---|
| Producer throughput (msg/s) | 103,273 · 105,937 · 106,469 (mean 105,226) | 113,610 · 114,881 · 113,446 (mean 113,979) | +8.3 % |
| Publish latency p50 (ms) | 965.6 · 938.5 · 940.5 | 877.1 · 864.8 · 877.6 | −7.9 % |
| End-to-end latency p50 (ms) | 980.5 · 948.2 · 954.4 | 894.5 · 897.0 · 892.4 | −6.9 % |
| End-to-end latency p99 (ms) | 1,122.3 · 1,073.2 · 1,096.7 | 1,039.4 · 1,382.4 · 1,073.2 | +6.2 % |
| Sampled maximum backlog | 25,875 · 26,765 · 49,855 | 43,953 · 90,782 · 56,146 | +86.2 % |
IoT telemetry high rate, unprofiled (end-to-end latency and backlog are the ranges over the 5 applications, and their change is that of the mean over the applications):
| Without | With | Change | |
|---|---|---|---|
| Producer throughput (msg/s) | 61,371 · 61,680 (mean 61,526) | 62,469 · 64,190 (mean 63,330) | +2.9 % |
| Publish latency p50 (ms) | 1,626.1 · 1,648.6 | 1,607.7 · 1,599.5 | −2.1 % |
| End-to-end latency p50 (ms) | 2,062–2,109 · 2,076–2,107 | 2,022–2,062 · 2,016–2,044 | −2.6 % |
| End-to-end latency p99 (ms) | 2,896–3,031 · 2,873–2,916 | 2,636–2,851 · 2,533–2,630 | −9.4 % |
| Sampled maximum backlog per application | 60,383–68,605 · 82,522–85,356 | 67,733–71,975 · 72,689–83,762 | −1.2 % |
Broker, profiled Key_Shared run (JFR recording and flame graphs of the measurement period):
| Without | With | Change | |
|---|---|---|---|
| Producer throughput (msg/s) | 101,116 | 108,700 | +7.5 % |
| Broker CPU samples per million messages | 6,389 | 5,756 | −9.9 % |
| Managed-ledger thread CPU samples per million messages | 913 | 845 | −7.4 % |
| Java heap allocation per message (allocation flame graph) | 1,814 bytes | 1,968 bytes | +8.5 % |
| Blocked time with an application frame (off-CPU) | 0.34 s | 0.46 s |
With the adaptive allocator the broker uses less CPU per message, including on the managed-ledger thread, which is the serial stage in the Key_Shared scenario, and every Key_Shared run with it had a higher throughput than every run without it; the high-rate runs with it were also faster. The p50 latencies drop with the throughput gain. In the Key_Shared scenario the p99 is within the run-to-run spread apart from one run with it (1,382 ms), and the sampled backlog peaks are higher (43,953–90,782 against 25,875–49,855); in the high-rate scenario the p99 is lower. The broker allocates 8.5 % more on the Java heap per message with the adaptive allocator (+154 bytes), which ZGC handles within this run without a visible cost. The allocation flame graphs of the first measurement of this change, where the difference was 13 %, show where it comes from:
| Heap allocation per message | Pooled | Adaptive |
|---|---|---|
UnpooledSlicedByteBuf from AbstractByteBuf.slice |
0 bytes | 262 bytes |
java.nio.DirectByteBuffer from PlatformDependent0.offsetSlice |
0 bytes | 149 bytes |
UnpooledDuplicatedByteBuf from AbstractByteBuf.duplicate |
0 bytes | 62 bytes |
| Recycled pooled derived buffers and other pooled allocator objects | 86 bytes | 0 bytes |
ResourceLeakDetector trace records |
144 bytes | 41 bytes |
retainedSlice() and retainedDuplicate() return a PooledSlicedByteBuf or PooledDuplicatedByteBuf from Netty's Recycler. AdaptivePoolingAllocator.AdaptiveByteBuf doesn't override them, so they fall back to AbstractByteBuf.slice() and duplicate(), which create an UnpooledSlicedByteBuf or UnpooledDuplicatedByteBuf on every call. A message's buffer is sliced or duplicated several times on its way through the broker: LengthFieldBasedFrameDecoder.extractFrame for each incoming frame (75 bytes per message), EntryImpl.create, createWithRetainedDuplicate and initializeMessageMetadataIfNeeded (115), OpAddEntry.initiate (34), ByteBufPair.Encoder.write (65) and BookKeeper's PerChannelBookieClient.addEntry (32).java.nio.DirectByteBuffer. AdaptiveByteBuf.setBytes(int, ByteBuf, int, int) copies through nioBuffer() and internalNioBuffer() of the underlying UnpooledDirectByteBuf, which create a new DirectByteBuffer view (PlatformDependent0.offsetSlice) for each call, mostly in BookKeeper's DigestManager.computeDigestAndPackageForSendingV2 (69 bytes per message) and in copies from sliced buffers (78). A pooled unsafe buffer copies by memory address without a view object.These objects are small and short-lived, the cheapest garbage for ZGC's young generation, and the broker still uses 9.9 % less CPU per message. The difference comes from Netty's adaptive allocator implementation (Netty 4.2.18) rather than from Pulsar: if AdaptiveByteBuf recycled its derived buffers and copied by memory address, most of it would go away.
Charts of the median unprofiled Key_Shared run of each side (without 105,937 msg/s, with 113,610 msg/s), as the run report renders them:
| Without | With |
|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
This change is a trivial rework / code cleanup without any test coverage.
Both scripts pass bash -n. The allocator selection itself is covered by the existing PulsarByteBufAllocatorTest and PulsarByteBufAllocatorTypeTest, which include the adaptive type and the named pulsar.allocator.default.type setting.
If the box was checked, please highlight the changes
Default values of configurations: the scripts select the adaptive allocator for Pulsar's default allocator; -Dpulsar.allocator.default.type=pooled in PULSAR_EXTRA_OPTS or BOOKIE_EXTRA_OPTS restores the pooled allocator.
This PR was prepared with AI assistance (Claude Code) and reviewed by a human contributor.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…llocator Netty's AdaptiveByteBufAllocator sizes its pooled chunks to the allocation pattern it sees, and Netty 4.2 already uses it as its own default. Pulsar's default allocator still uses PooledByteBufAllocator. Make the adaptive allocator the default for Pulsar's general operations in conf/pulsar_env.sh and conf/bkenv.sh, with -Dpulsar.allocator.default.type=adaptive, and pin Netty's own default with -Dio.netty.allocator.type=adaptive. The options are prepended to OPTS, so that the configured options override them. Assisted-by: Claude Code (claude-opus-5-5)
There was an error while loading. Please reload this page.
…llocator (apache#26720) (cherry picked from commit d649aac)
…llocator (apache#26720) (cherry picked from commit d649aac)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.