RongtongJin opened a new issue, #11508:
URL: https://github.com/apache/rocketmq/issues/11508

   ### Before Creating the Enhancement Request
   
   - [x] I have confirmed that this should be classified as an enhancement 
rather than a bug/feature.
   
   
   ### Summary
   
   Avoid comparing unchanged TimerWheel pages with the mapped file on every 
ordinary flush. Track modified logical 4 KiB pages, scan only those pages, and 
preserve the existing force call, file format and flush schedule.
   
   ### Motivation
   
   On develop at `164322b91e26fca2a53e6580003e582ff0621514`, 
`TimerWheel.flush()` visits every byte in the wheel even when only a small 
fraction of slots changed. This consumes background CPU regardless of the 
clean-page fraction. Workloads with sparse slot updates can avoid that repeated 
comparison work without changing message access, consumer count, thread 
settings or capacities.
   
   Actual earlier startup-agent prototype measurements on a downstream 
distribution on Hygon used four independent SimpleConsumers, the original 
access/ACK policy and thread/capacity settings, 1,000 messages/s, 120 s warmup 
and 300 s measurement. Every measured round sent and ACKed 300,000 messages.
   
   | 1 KiB retest | Broker CPU s / million inputs, OFF -> ON | Broker CPU 
reduction | Broker + Proxy reduction | Candidate ACK-complete P99 | CPU + P99 
gates |
   | --- | ---: | ---: | ---: | ---: | --- |
   | Queue sampler | 930.210 -> 850.277 | 8.59% | 4.34% | 9.163 / 8.636 ms | 
PASS |
   | Array sampler, independent cross-check | 942.931 -> 848.893 | 9.97% | 
6.31% | 8.338 / 8.053 ms | PASS |
   
   Each sampler had two OFF and two ON rounds. CPU is normalized by actual 
successful inputs. Gates: Broker CPU/input reduction >=5%; each ON 
Delivery/ACK-complete/Scheduled-ACK P99 <=110% of its same-sampler 
two-OFF-round P99 mean; hard Send P99 <=20 ms and the other three <=50 ms. 
These are fixed-rate savings, not maximum-throughput measurements.
   
   The retest passed these gates. An earlier 1 KiB campaign had one 
relative-tail failure; the PR retains that history and observer-effect 
analysis. The later pass does not prove that earlier failure was solely a test 
artifact.
   
   These percentages describe the earlier prototype, **not a benchmark of the 
Apache source commit**. The environment used loopback networking in one 
isolated Pod, two repeats per condition, Broker 4 CPU/2 GiB, Proxy 1 CPU, and a 
client using Serial GC. This is a general optimization tested on Hygon, not an 
architecture-exclusive claim.
   
   ### Describe the Solution You'd Like
   
   1. Initialize an atomic dirty flag per logical 4 KiB page.
   2. Publish the affected page in `finally` after both `putSlot` overloads and 
`reviseSlot`, including partial-write exceptions.
   3. Claim and clear a page before copying it. A writer publishing after that 
claim leaves the page pending for a later flush. Restore the current flag if 
copying throws.
   4. Keep the original byte comparison/difference writes within claimed pages 
and retain `MappedByteBuffer.force()` even when all flags are clean.
   5. Preserve slot/file layout and the independent full snapshot backup path.
   
   Under existing single-flusher usage, completed writes converge to the 
persisted buffer after writers quiesce and a successful flush; this does not 
make concurrent slot updates transactional. The proposed source change passed 
14 focused JUnit tests (6 existing + 8 new regressions) and 5,237 separate 
oracle checks, with production/JUnit compilation using `--release 8` and 
execution on JDK 21. Correctness reasoning, exception/reopen/concurrency 
coverage and the exact test scope are in #11507.
   
   ### Describe Alternatives You've Considered
   
   - A whole-wheel dirty flag can skip completely idle flush scans, but still 
scans the entire wheel whenever any slot changes.
   - Reducing flush frequency or skipping force would change the persistence 
schedule or retry behavior; this proposal keeps them.
   - Reducing consumers, threads or initial capacities does not remove the 
full-scan work and is outside this change.
   
   ### Additional Context
   
   Implementation and detailed measurements: #11507 (Draft).
   
   Related: #10527 discusses several auxiliary-component optimizations, 
including a whole-wheel dirty flag. This issue isolates page-level scan 
elimination while preserving force behavior. The separate snapshot feature is 
unaffected.
   
   Savings depend on the fraction of clean pages. Dense updates or flag 
contention can reduce the benefit; no speedup is claimed for the 
snapshot-backup path.


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

Reply via email to