Skip to content

perf(journal): stop formatting a path per WAL entry at checkpoint - #5106

Open
krishvishal wants to merge 2 commits into
masterfrom
journal-checkpoint-segment-paths
Open

krishvishal wants to merge 2 commits into
masterfrom
journal-checkpoint-segment-paths

Conversation

@krishvishal

@krishvishal krishvishal commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

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 PathBuf for every entry and sorted them in a BTreeSet to 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. Now referenced_segments dedups 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%.

Workload p99.9 before p99.9 after max before max after
12 partitions, 1 KB, 125 MB/s (3 runs each) 8.0 ms 4.3 ms 32 ms 15 ms
25 partitions, 1 KB, 1 message per batch (2 runs each) 31 ms 6.5 ms 149 ms 43 ms
12 partitions, 100 B, 120 MB/s (1 run each) 8.5 ms 4.8 ms 38 ms 19 ms

A frame-pointer perf profile put 71% of the rewrite's CPU in this path listing.

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.
@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Nov 28, 2026
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.77%. Comparing base (b179e96) to head (0ff3328).

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     
Components Coverage Δ
Rust Core 89.43% <100.00%> (-4.13%) ⬇️
Java SDK 81.03% <ø> (ø)
C# SDK 86.32% <ø> (-0.09%) ⬇️
Python SDK 85.39% <ø> (ø)
PHP SDK 90.42% <ø> (ø)
Node SDK 97.27% <ø> (+<0.01%) ⬆️
Go SDK 73.82% <ø> (+0.14%) ⬆️
C++ SDK 85.44% <ø> (ø)
Files with missing lines Coverage Δ
core/journal/src/partition_journal.rs 95.39% <100.00%> (+0.04%) ⬆️

... and 453 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread core/journal/src/partition_journal.rs Outdated
.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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread core/journal/src/partition_journal.rs Outdated
// 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@github-actions github-actions Bot added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author PR is waiting on author response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants