Skip to content

perf(durable-streams-rust): per-shard checkpoint triggers — interval knob + retained-WAL size budget#4704

Merged
balegas merged 3 commits into
perf/wal-checkpoint-syncfsfrom
perf/wal-checkpoint-sizetrigger
Jul 13, 2026
Merged

perf(durable-streams-rust): per-shard checkpoint triggers — interval knob + retained-WAL size budget#4704
balegas merged 3 commits into
perf/wal-checkpoint-syncfsfrom
perf/wal-checkpoint-sizetrigger

Conversation

@balegas

@balegas balegas commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Stacked on #4697. Replaces the hardcoded 3s all-shards checkpoint wave with a per-shard dual trigger:

  • --wal-checkpoint-interval-ms — time trigger, default 3000 (= old behavior).
  • --wal-checkpoint-wal-bytes — size trigger (0 = off): checkpoint a shard as soon as ITS retained WAL exceeds the budget.

Why

The checkpoint's only job is bounding retained-WAL size = crash-replay time: acks never gate on it and reads never touch the WAL (reads are sendfile from the data file's page cache, which is written before the WAL ack barrier). So cadence is purely a replay-time budget — the size trigger makes that budget explicit, and shards self-stagger by their own write rates instead of storming the device in a synchronized wave. Each shard's clock restarts when it finishes; an in-flight guard prevents re-firing a slow shard; due shards still checkpoint concurrently.

Results (c4d-standard-64-lssd, split-lane layout, --wal-shards 5 --wal-checkpoint-syncfs on; suite wal-sizetrigger)

arm 10k streams 100k streams
ref-3s (timer, control) 293.9k 275.3k
size-1g (--wal-checkpoint-wal-bytes 1GiB, 60s fallback) 309.6k 303.2k
checkpoint-off ceiling (wal-splitlane) 305.1k 306.0k

The size trigger recovers the entire 7–11% checkpoint cost — throughput at the ckpt-off ceiling with replay bounded at ≤1 GiB retained WAL per shard.

Verification

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y3x7bcT9vLGiT4tXZeQpnk

…knob + retained-WAL size budget

Replace the hardcoded 3s all-shards checkpoint wave with a per-shard dual
trigger: --wal-checkpoint-interval-ms (time, default 3000 = old behavior) and
--wal-checkpoint-wal-bytes (size, 0 = off): checkpoint a shard as soon as its
retained WAL exceeds the budget. Rationale (wal-decomp-lane0, 2026-07-13):
acks never gate on checkpoint and reads never touch the WAL, so checkpoint
frequency is purely a replay-time budget — a size trigger makes that budget
explicit and lets shards self-stagger by their own write rates instead of
storming the device together. Each shard's clock restarts when its checkpoint
finishes, an in-flight guard prevents re-firing a slow shard, and due shards
still checkpoint concurrently.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3x7bcT9vLGiT4tXZeQpnk

@github-actions github-actions Bot left a comment

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.

Auto-approved: all changes are within the durable streams package.

balegas and others added 2 commits July 13, 2026 18:49
…-path configuration

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3x7bcT9vLGiT4tXZeQpnk
…ed; note the separate ~1M-stream wall

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3x7bcT9vLGiT4tXZeQpnk
@balegas

balegas commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Stacked validation complete (wal-stacked-1m): this PR's size trigger + exclusive pinned cores + split-lane layout together = 382.7k ops/s @100k streams (vs 10.4k pre-campaign, 37×; memory-mode ceiling 512k). WAL_TUNING.md in this branch documents the full ideal configuration.

Extreme-cardinality check on the same config: 244k @500k, 56k @1m — a separate, new mechanism appears near 1M streams (fd-per-stream vs nofile ceiling / 1M-file directory / map working set — not the checkpoint storm this stack fixed). Tracked as the next investigation.

@balegas
balegas merged commit 586bede into perf/wal-checkpoint-syncfs Jul 13, 2026
9 of 12 checks passed
@balegas
balegas deleted the perf/wal-checkpoint-sizetrigger branch July 13, 2026 21:54
balegas added a commit that referenced this pull request Jul 14, 2026
…yncfs checkpoints, per-shard triggers, stream lanes (#4697)

Eliminates the WAL write cardinality cliff end-to-end. Formerly a 4-PR
stack (#4704, #4705, #4707 folded in here). Full deployment guidance:
`WAL_TUNING.md` (in this PR). **Validated by the canonical benchmark
campaign 2026-07-14** (ds-bench#6: `results/REPORT.md` +
`PROVENANCE.md`) run against this PR's head.

## The problem

WAL-durable write throughput collapsed with stream count: **10.4k ops/s
@100k streams** (vs ~110k @10k), degrading further under load. Two
compounding causes:
1. The checkpoint issued **one `fdatasync` per touched stream** — an
O(N) barrier storm sharing the device with commit fsyncs.
2. At extreme cardinality (~1M), checkpoint **writeback amplification**
(~40× for small appends: dirty page + inode + extents + journal per
file) saturated the single data device — one `syncfs` measured at 60–74
s.

## The changes

| commit | what | measured effect |
|---|---|---|
| syncfs checkpoint | one `syncfs` barrier per stream lane instead of
O(N-touched) `fdatasync` (unconditional on Linux) | +51% at the 100k
cliff |
| per-shard checkpoint triggers | `--wal-checkpoint-interval-ms` +
`--wal-checkpoint-wal-bytes` (retained-WAL/replay budget; shards
self-stagger, in-flight guard, panic-safe) | checkpoint cost ≈ 0 |
| `--stream-lanes N` | hash stream data files across per-device lane
dirs; N parallel per-lane syncfs; lane count persisted + validated on
open | 1M wall broken: 68k → **212k** (syncfs 60–74s → 6–11s) |
| cleanup | dead knobs removed (`--wal-fsync-parallel`, meta gates,
meta-sweep toggles, `--tier local`); memory×tier rejected at startup;
flag-clear WAL records decode as torn | smaller, safer surface |

## Results — canonical campaign 2026-07-14 (this PR's head, ideal
configuration)

**Write saturation** (`canonical-write`, 256 B appends,
c4d-standard-64-lssd, 3 stream lanes + 3 WAL lanes, pinned cores):

| streams | wal-ideal | memory (no-fsync ceiling) |
|---|---|---|
| 10k | 417k | 680k |
| 100k | **382k (−8%, no cliff)** | 632k |

vs 10.4k @100k pre-campaign = **37×**. At extreme cardinality (same
config): 285k @500k, 212k @1m.

**Reads** (unchanged by this PR, revalidated): catch-up 2.27–2.74 GiB/s,
cardinality-flat 10→100 streams; SSE tail p99 2–3 ms up to 2048
connections.

**Mixed interference**: 100k concurrent catch-up readers cost a pinned
50k ops/s write load nothing (303 MiB/s replay served alongside). The
2026-07-02 memory-mode delivery collapse no longer reproduces on this
build: delivery tracks writes 1:1 to 127k/s (wal: keeps pace to ~40k,
caps ~64k del/s at full write saturation).

## Correctness

- The recoverability contract is unchanged: ack = WAL group-commit
fdatasync; a WAL segment is recycled only after its records' stream
bytes are fsynced AND the durable-tail map is persisted. All knobs only
change *when/how* that sequence runs.
- 105/105 tests: syncfs crash-recovery e2e, 3-lane crash-recovery +
layout-spread + lane-mismatch rejection, memory-mode sidecar-skip
regression, randomized crash sim.
- CI green including all four conformance configs (`memory`,
`wal-default`, `wal-read-offload-always`, `wal-resident-cache`).
- Defaults preserve behavior except syncfs-on-Linux (extensively
measured); `--stream-lanes` defaults to 1 = byte-identical layout.
Changeset: patch.

## Follow-ups (tracked)

- #4695 log-structured store (removes per-file writeback amplification
structurally — the residual 100k→1M slope)
- #4696 cold tier as durable store
- #4706 lazy fd management (1 fd/live stream = 96% of the 1,048,576
ceiling at 1M streams)
- #4709 io_uring experiment (measured as a regression in v1 form;
default off, not for merge)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Y3x7bcT9vLGiT4tXZeQpnk

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant