Denovo1998 commented on PR #24739:
URL: https://github.com/apache/pulsar/pull/24739#issuecomment-3619318077
In the current `master` branch the implementation uses `StampedLock` and is
heavily optimized for **pure read (`contains`) throughput** via optimistic
reads.
In the new version (`Denovo1998:bucket_delivery_tracker_optimize`) I
switched to a standard **read–write lock**, so it’s expected that a *pure*
`contains` micro-benchmark cannot beat the `StampedLock` version.
However, delayed-message workloads are not “pure read” – they are a mix of:
* `addMessage` (adding new delayed messages),
* `remove/ack` / cleanup,
* occasional `contains` checks.
So I focused on the **mixed-operation benchmarks**, which better reflect
real usage.
From the JMH results:
* **Write path (`benchmarkConcurrentAddMessage`)**
* `master`: ~6k ops/s
* new version: **5M–11M ops/s**
→ roughly **three orders of magnitude faster** on `addMessage`.
* **Pure read (`benchmarkConcurrentContainsMessage`)**
* `master`: ~80M–90M ops/s
* new version: ~2M–3M ops/s
→ here `master` is much faster, which matches the `StampedLock` design
goal.
* **Mixed operations (1 thread, `benchmarkMixedOperations`)**
For typical read/write mixes:
* 50/50, 70/30, 80/20: the new version is about **hundreds of times
faster** (e.g. 50/50 goes from ~13k ops/s to ~12.6M ops/s).
* Even at 90% read / 10% write, the new version is still **slightly faster
overall**.
* **Mixed operations, high contention (32 threads,
`benchmarkHighContentionMixedOperations`)**
* 50/50: ~**2.9×** faster
* 70/30: ~**1.5–1.6×** faster
* 80/20: ~**1.3–1.4×** faster
* 90/10: still **5–10% faster** end-to-end
So the trade-off is:
* We **give up some extreme pure-read throughput** from the `StampedLock`
implementation;
* In exchange, we **dramatically improve write performance** and get
**consistent wins in mixed read/write workloads**, which is closer to how
delayed messages are actually used in production.
---
1. Current PR optimized implementation.
https://gist.github.com/Denovo1998/d470ea939fc9337523545525539b8f5f
https://gist.github.com/Denovo1998/74077064f0aa7c1119c6e627a083262a
<img width="3178" height="6945" alt="CleanShot 2025-12-06 at 10 21 28@2x"
src="https://github.com/user-attachments/assets/9542ffbf-9c3c-4369-893b-95c6d840b3a1"
/>
---
2. Code branch implemented using synchronized and StampedLock.
https://gist.github.com/Denovo1998/02075b374a5f00771ac6d32809ac4036
https://gist.github.com/Denovo1998/19b0483cd1f9ca06b17ac434fe402a74
<img width="3180" height="6950" alt="CleanShot 2025-12-06 at 10 24 14@2x"
src="https://github.com/user-attachments/assets/fad3a800-efc7-4d99-9fae-d97f6b3d8b45"
/>
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]