Skip to content

perf(partitions): spread WAL checkpoint starts across partitions - #5113

Open
krishvishal wants to merge 1 commit into
journal-checkpoint-segment-pathsfrom
wal-checkpoint-spread
Open

krishvishal wants to merge 1 commit into
journal-checkpoint-segment-pathsfrom
wal-checkpoint-spread

Conversation

@krishvishal

@krishvishal krishvishal commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Rationale

Every partition started a WAL checkpoint once its byte budget was half full. Under equal load the partitions reach that mark together, so all shards checkpoint in the same second and every partition stalls at once. With 25 partitions on 8 shards, 18 checkpoints started in one second, once every 50 s, and those seconds held the worst latency of the run.

What changed?

The mark is now drawn per partition from 3/8 to 5/8 of wal_bytes_max, and drawn again after each checkpoint. A mark fixed per partition left some partitions with a low mark for good, which cost 7-10% more checkpoints in the benchmark. Redrawn, the rate rises by about 2% on average, and the runs below took 2-7% more checkpoints. The mark stays at least one maximum-size prepare below the budget, so an append that does not fit always finds a checkpoint due.

Local Execution

On 25 partitions, p99.9 fell by 44% and max by 76%. The busiest second went from 18 checkpoint starts to 3.

Workload p99 before p99 after p99.9 before p99.9 after max before max after
25 partitions, 1 KB, 1 message per batch 1.88 ms 1.64 ms 6.87 ms 3.83 ms 61 ms 15 ms
12 partitions, 1 KB, 125 MB/s, run 1 1.70 ms 2.62 ms 3.95 ms 5.38 ms 16 ms 27 ms
12 partitions, 1 KB, 125 MB/s, run 2 1.39 ms 1.38 ms 4.10 ms 3.80 ms 38 ms 32 ms

12 partitions is neutral: only 4-9 checkpoints started in the same second there, so there was less to spread. In run 1 of this branch, one 20 s window took outside CPU load: machine-wide CPU rose from 19% to 28-44% while checkpoints ran as usual.

A partition starts a WAL checkpoint once its byte budget is half full.
Under equal load the partitions reach that mark together, so all shards
checkpoint in the same second and every partition stalls at once. With
25 partitions on 8 shards, 18 checkpoints started in one second, once
every 50 s, and those seconds held the worst latency of the run.

The mark is now drawn per partition from 3/8 to 5/8 of the budget, and
drawn again after each checkpoint so no partition keeps a low mark. The
average checkpoint rate rises by about 2%. The mark stays at least one
maximum-size prepare below the budget, so an append that does not fit
always finds a checkpoint due.

Local OMB, one node, replicated: publish p99.9 went from 6.9 to 3.8 ms
and max from 61 to 15 ms on 25 partitions with one message per batch.
12 partitions at 125 MB/s did not change.
@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Nov 29, 2026
@krishvishal
krishvishal added this pull request to stack #5114 November 29, 2026 07:36
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@                          Coverage Diff                           @@
##             journal-checkpoint-segment-paths    #5113      +/-   ##
======================================================================
+ Coverage                               88.77%   92.26%   +3.49%     
  Complexity                               4366     4366              
======================================================================
  Files                                    1570     1592      +22     
  Lines                                  366680   436888   +70208     
  Branches                               294913   365122   +70209     
======================================================================
+ Hits                                   325515   403105   +77590     
+ Misses                                  34869    28170    -6699     
+ Partials                                 6296     5613     -683     
Components Coverage Δ
Rust Core 93.56% <100.00%> (+4.12%) ⬆️
Java SDK 81.03% <ø> (ø)
C# SDK 86.34% <ø> (+0.01%) ⬆️
Python SDK 85.41% <ø> (+0.01%) ⬆️
PHP SDK 90.42% <ø> (ø)
Node SDK 97.26% <ø> (-0.01%) ⬇️
Go SDK 73.85% <ø> (+0.02%) ⬆️
C++ SDK 85.44% <ø> (ø)
Files with missing lines Coverage Δ
core/partitions/src/persistence.rs 93.62% <100.00%> (+0.14%) ⬆️

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

// The minimum budget is two records of the largest prepare.
let largest_record = PARTITION_WAL_CAPACITY_MIN / 2;
let offset = splitmix64(splitmix64(group) ^ checkpoint_op) % (capacity / 4 + 1);
(capacity / 8 * 3 + offset).min(capacity.saturating_sub(largest_record))

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.

[nit] At the minimum budget of 128 MiB + 8 KiB this cap equals capacity / 2, so half the draws clip to exactly the old fixed mark and those partitions still start checkpoints together. The clip lasts up to about 171 MiB, yet the doc comment above and core/server/config.toml:1127 state 3/8 to 5/8 for every budget.

const CHECKPOINTS: u64 = 1000;
let capacity = PARTITION_WAL_BYTES_MAX;
let group = IggyNamespace::new(1, 1, 0).inner();
// Checkpoints per byte against a mark at half, in thousandths: a

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.

[nit] Summing half / mark per checkpoint gives about 1.02, but that is the rate of marks fixed per partition. With a redrawn mark, a partition checkpoints once per mean mark, which is exactly half, so its rate equals the old one, as the test name says. The 1000..1040 range accepts both, and the PR body repeats the 2% claim.

&& (self.checkpoint_needed.get()
|| self.retained_bytes.get() + self.queued_bytes.get() + self.in_flight_bytes.get()
>= self.capacity / 2
>= checkpoint_bytes(self.capacity, self.group, self.checkpoint.get())

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.

[nit] Moving the trigger leaves core/integration/tests/server/disk_usage.rs:57 saying the 18.3 MiB burst is measured against half the 256 MiB budget. The lowest mark is now 3/8, which is 96 MiB. The test still holds, but its comment names a trigger that no longer exists.

@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