Repository navigation
[ISSUE #10432] Optimize RocksDB ConsumeQueue sequential reads with a bounded iterator - #11596
Open
Drifter-yh wants to merge 1 commit into
Open
Drifter-yh wants to merge 1 commit into
Drifter-yh wants to merge 1 commit into
Conversation
…ith a bounded iterator
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #11596 +/- ##
==========================================
Coverage 50.23% 50.24%
- Complexity 14598 14605 +7
==========================================
Files 1391 1391
Lines 103467 103471 +4
Branches 13559 13557 -2
==========================================
+ Hits 51981 51993 +12
+ Misses 45237 45235 -2
+ Partials 6249 6243 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
CI update:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Brief Description
RocksDBConsumeQueueTable#rangeQuerycurrently builds one RocksDB key per ConsumeQueue offset and callsmultiGetwith 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#scanCQcreates aRocksIterator, seeks to the start key once, and iterates values in key order.ReadOptions#setIterateUpperBoundbounds the scan atstartIndex + num, so it cannot walk into a neighbouring queue or topic even when the next queue's offset would line up.rangeQuerypreserves the existing gap semantics: it stops at the first offset that is not exactlystartIndex + returnedCount. Values are therefore still consecutive CQ units starting atstartIndex, and callers can keep advancing offsets by one per returned unit.num == 1) still uses a point get, because iterator setup costs more than one lookup.iteratorWhenUseRocksdbConsumeQueue,RocksDBReusableIterator, LMQ behavior) is unchanged.Benchmark
Local harness in a single JVM (storage + table, no running broker): 500,000 consecutive CQ entries for one topic/queue (28-byte values), written through the production
buildAndPutCQByteBufferpath, 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.1develop@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):
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?
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 thanInteger.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 teston Windows 11, Microsoft OpenJDK 17.0.14: 27 tests passed, 0 failures/errors/skips.mvn -B -ntp -pl store -am -DskipTests packagesucceeds; Checkstyle and SpotBugs pass.git diff --checkpasses.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.