Skip to content

perf(event-log): checkpoint the WAL every 4,000 pages - #7212

Open
YongGoose wants to merge 1 commit into
apache:mainfrom
YongGoose:perf/event-log-wal-checkpoint
Open

YongGoose wants to merge 1 commit into
apache:mainfrom
YongGoose:perf/event-log-wal-checkpoint

Conversation

@YongGoose

Copy link
Copy Markdown
Member

Supersedes #6700, which GitHub closed when rust-preview was deleted after the switch to main. Rebased onto main (73f2333), where cargo nextest run -p maka-event-log passes (47 tests). The measurement below was taken on rust-preview 19e6a11, which main now contains.

Summary

The event log used SQLite's default auto-checkpoint of 1,000 pages. Every commit rewrites the same hot pages, such as the right edge of event_log, sqlite_sequence and the per-session index leaves, so each checkpoint cycle copied them back into the database again.

This sets PRAGMA wal_autocheckpoint = 4000 on the writer connection. Hot pages are copied back a quarter as often. The PR originally used 10,000 pages; #7115 has since capped the runtime WAL with journal_size_limit = 16777216. 4,000 pages of 4 KiB (about 15.6 MiB) stay under that limit. At 10,000 pages, the WAL would reach about 40 MiB before every checkpoint and then be truncated back to 16 MiB, undoing that cap.

This only addresses the checkpoint share of #6699. The rest comes from how many pages each event touches, which needs a design decision.

Refs #6699

Verification

Re-measured on rust-preview 19e6a11 (macOS 27.0.1, arm64), with one release build that reads the checkpoint interval from an environment variable for the comparison only. A production maka host serve ran scripted repair work against a loopback OpenAI-compatible model: each maka run session ran 24 cycles of Read, Shell (grep), Shell (a small Python check), Edit, Shell, each call in its own exec cell. Writes come from proc_pid_rusage on the Host process. Every run finished all 1,920 tool calls without a tool failure, and every edited file reached the expected value.

16 concurrent sessions, 1,920 tool calls per run, runs alternated:

wal_autocheckpoint Storage writes / call Logical writes / call WAL peak Wall time
1,000 (current) 27,655 KiB, 27,422 KiB 24,097 KiB, 23,973 KiB 41.0 MiB, 16.0 MiB 546 s, 504 s
4,000 (this PR) 24,614 KiB, 24,540 KiB 23,056 KiB, 23,147 KiB 30.1 MiB, 28.0 MiB 501 s, 468 s
10,000 23,133 KiB, 23,068 KiB 22,829 KiB, 22,943 KiB 42.5 MiB, 42.4 MiB 472 s, 484 s
  • 4,000 pages cut storage writes by about 11%, and 10,000 by about 16%. Including the checkpoint at Host shutdown changes each figure by less than 20 KiB per call, so the saving isn't deferred to shutdown.
  • The WAL peak exceeds 16 MiB even at 1,000 pages. journal_size_limit truncates the WAL only when it resets, and concurrent readers can keep it growing until then. That's unchanged here.
  • One session at a time (2 × 120 tool calls, one run each): 21,514 KiB per call at 1,000 pages and 19,882 KiB at 4,000. The second run overlapped heavy load from another process (668 s against 156 s), so treat it as a sanity check only.
  • The machine was running a VM under heavy load during the campaign (load average 85–105), so wall times are noisy.
  • Absolute numbers are about ten times those in Event log writes 1.2–2.6 MiB per tool call; default WAL checkpoints account for much of it #6699 (1.5–2.6 MiB per call). That workload made direct tool calls; this one runs each call in an exec cell through maka run, and perf(agent,event-log): fix Scenario M O(1) scaling, cell/catalog leaks, history indexes, and RequestComposition dedup #7115 has changed the tables since. I haven't broken down where the additional writes go.
  • cargo nextest run -p maka-event-log: 47 passed.
  • node scripts/ci.mjs check format passes.

Not run: the full root suite and the Windows and Linux suites.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code built the measurement harness, ran the comparison and the checks above, and wrote the change. The commit carries Generated-by: Claude Code.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

There's no new test. This changes a storage tuning value, not behavior, and a test asserting the pragma would only restate the code. The measurement above is the evidence.

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

The event log used SQLite's default auto-checkpoint of 1,000 pages. Every
commit rewrites the same hot pages, so each checkpoint cycle copied them
back into the database again. Checkpointing every 4,000 pages copies them
back a quarter as often, and 4,000 pages of 4 KiB still fit within the
16 MiB journal_size_limit set in apache#7115.

With 16 concurrent sessions running scripted repair work, storage writes
fell from about 27.0 MiB to 24.0 MiB per tool call. Wall time did not
regress.

Generated-by: Claude Code
@github-actions github-actions Bot added the effort/XS Under 10 readable lines label Nov 23, 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

effort/XS Under 10 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant