Repository navigation
perf(journal): stop formatting a path per WAL entry at checkpoint - #5106
krishvishal wants to merge 2 commits into
Conversation
A partition checkpoint rewrites its WAL and lists the segment files the old and the new entries still reference. The list built a PathBuf for every entry and sorted them all in a BTreeSet, twice per rewrite, to find one or two segment names. With 10k-30k entries per checkpoint that held the shard thread for 5-18 ms, and every partition on the shard waited. The list now dedups (generation, start_offset) keys and formats paths only for distinct segments. The rewrite copies only the entries at or above the checkpoint instead of every entry. Local OMB, one node, replicated: publish p99.9 went from 8.0 to 4.3 ms on 12 partitions at 125 MB/s, and from 31 to 6.5 ms on 25 partitions with one message per batch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5106 +/- ##
============================================
- Coverage 92.26% 88.77% -3.50%
+ Complexity 4367 4366 -1
============================================
Files 1592 1570 -22
Lines 436807 366680 -70127
Branches 365039 294913 -70126
============================================
- Hits 403019 325515 -77504
- Misses 28172 34869 +6697
- Partials 5616 6296 +680
🚀 New features to boost your workflow:
|
| .collect(); | ||
| for (op, entry) in previous_entries { | ||
| if op < checkpoint || truncate.is_some_and(|from| op >= from) { | ||
| if truncate.is_some_and(|from| op >= from) { |
There was a problem hiding this comment.
[simplify] The comment above says only the kept tail is copied, but with truncate set the Vec still holds every op from from upward and the loop skips them one by one. reset passes Some(0), so it collects the whole tail. The ops ascend, so .take_while(|&(op, _)| truncate.is_none_or(|from| op < from)) before collect can replace the continue.
| // Thousands of entries name a few segments, in runs. A path per entry made | ||
| // every checkpoint format and sort them all on the shard thread. | ||
| let mut keys = BTreeSet::new(); | ||
| let mut last = None; |
There was a problem hiding this comment.
[simplify] The last run check repeats what BTreeSet::insert already does with a repeated key, and it saves a comparison or two against a set of a few keys. Collecting the (generation, start_offset) keys straight into the BTreeSet gives the same result without last and the branch, as retain_segment_inodes does with insert alone.
Rationale
A partition checkpoint held its shard thread for 5-18 ms, and every partition on that shard waited. Under OMB load that showed up as a p99.9 several ms above Kafka's.
What changed?
Before, the WAL rewrite at checkpoint built a
PathBuffor every entry and sorted them in aBTreeSetto find the one or two segments the entries reference. It did that for the old and the new entries, so 10k-30k paths per checkpoint. Nowreferenced_segmentsdedups the(generation, start_offset)keys and formats a path only for each distinct segment, and the rewrite copies only the entries at or above the checkpoint instead of the whole map. The returned paths are the same.Local Execution
OMB on one local node, durability
replicated, master vs this branch, runs alternated:Across the three workloads, p99.9 latency fell by 56.3% on average, and observed maximum latency fell by 58.1%.
A frame-pointer perf profile put 71% of the rewrite's CPU in this path listing.