Drifter-yh opened a new pull request, #11596:
URL: https://github.com/apache/rocketmq/pull/11596
### Which Issue(s) This PR Fixes
- Fixes #10432
### Brief Description
`RocksDBConsumeQueueTable#rangeQuery` currently builds one RocksDB key per
ConsumeQueue offset and calls `multiGet` with all of them. The common read path
(`iteratorWhenUseRocksdbConsumeQueue=true`, `RocksDBReusableIterator`) requests
a contiguous batch, so those keys are adjacent in the ConsumeQueue column
family.
This change replaces the N point lookups with one bounded iterator scan:
- `ConsumeQueueRocksDBStorage#scanCQ` creates a `RocksIterator`, seeks to
the start key once, and iterates values in key order.
`ReadOptions#setIterateUpperBound` bounds the scan at `startIndex + num`, so it
cannot walk into a neighbouring queue or topic even when the next queue's
offset would line up.
- `rangeQuery` preserves the existing gap semantics: it stops at the first
offset that is not exactly `startIndex + returnedCount`. Values are therefore
still consecutive CQ units starting at `startIndex`, and callers can keep
advancing offsets by one per returned unit.
- A request for a single entry (`num == 1`) still uses a point get, because
iterator setup costs more than one lookup.
- The external iterator contract (`iteratorWhenUseRocksdbConsumeQueue`,
`RocksDBReusableIterator`, LMQ behavior) is unchanged.
### Benchmark
Local harness in one broker JVM: 500,000 consecutive CQ entries for one
topic/queue (28-byte values), written through the production
`buildAndPutCQByteBuffer` path, flushed and compacted. Each measured request
uses a random start offset ("random") or advances by the batch size
("sequential"). 3,000 warmup + 10,000 measured calls per data point, mean
latency. JDK 17.0.14, Windows 11, i9-13900HX, RocketMQ 5.5.1 `develop` @
`8764dd7`. "Before" is the removed multiGet implementation executed against the
same DB in the same JVM; "after" is this PR.
Warm block cache (dataset is smaller than the 1 GB CQ block cache):
| batch | before random (µs) | after random (µs) | before sequential (µs) |
after sequential (µs) |
|------:|-------------------:|------------------:|-----------------------:|----------------------:|
| 1 | 10.39 | 7.78 | 10.26 | 5.56 |
| 2 | 14.93 | 13.96 | 12.16 | 12.00 |
| 4 | 21.67 | 13.89 | 17.89 | 12.16 |
| 8 | 34.99 | 16.04 | 32.03 | 13.80 |
| 16 | 58.55 | 19.73 | 59.13 | 15.52 |
| 32 | 117.95 | 26.17 | 112.12 | 25.14 |
| 64 | 211.11 | 40.77 | 211.34 | 38.12 |
| 128 | 410.36 | 67.09 | 411.41 | 67.09 |
| 256 | 826.65 | 119.96 | 827.89 | 119.66 |
The default consumer batch size is 32, where this is roughly a 4.5x latency
reduction (78% lower). Batch 1 uses the point-get path.
After a RocksDB restart with a fresh block cache (500 random queries, OS
page cache warm): batch 32 went from 178.96 µs to 96.22 µs, and batch 64 from
302.94 µs to 129.56 µs. So the iterator path also wins when blocks are not
cached, and does not add read-ahead that hurts random reads.
### How Did You Test This Change?
- New `RocksDBConsumeQueueTableRangeQueryTest` (10 cases, real RocksDB):
consecutive offsets and order, gap at the start, gap in the middle, stop at
requested count, stop at end of available offsets, no crossing into another
queue (with an intentionally colliding offset), no crossing into another topic,
offsets larger than `Integer.MAX_VALUE`, single-entry and zero-count requests.
- `mvn -B -ntp -pl store -am
-Dtest=RocksDBConsumeQueueTableRangeQueryTest,RocksDBConsumeQueueTest,RocksDBConsumeQueueStoreTest,RocksDBConsumeQueueTableTest,RocksDBConsumeQueueOffsetTableTest
-Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test` on Windows
11, Microsoft OpenJDK 17.0.14: 27 tests passed, 0 failures/errors/skips.
- `mvn -B -ntp -pl store -am -DskipTests package` succeeds; Checkstyle and
SpotBugs pass.
- `git diff --check` passes.
The benchmark harness is a local test, not committed, to avoid adding a slow
and machine-dependent test to CI. I can attach it if you want to reproduce the
numbers.
AI assistance was used for analysis, implementation, and tests; the changes
were reviewed and tested as described above.
--
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]