Skip to content

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

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

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

Conversation

@YongGoose

@YongGoose YongGoose commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

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

@Astro-Han Astro-Han 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.

I reviewed the one-file change at 3e24b44880a4af48d12dac1fea58eab7223c1353 and traced execution-mode writer opening into schema::initialize_connection. The patch changes the connection's automatic WAL checkpoint threshold from SQLite's default 1,000 pages to 10,000 after migrations; it preserves synchronous=FULL and does not change a database schema, migration, or wire format.

No confirmed P0–P2 finding. I executed the exact old/new initialization PRAGMA strings against real SQLite 3.45.1 in a controlled comparison with 1,500 commits repeatedly updating 16 rows. The main database file's modification timestamp changed at a checkpoint once with the old threshold and zero times with the new one; the WAL files were about 4.12 MB and 6.32 MB respectively. Both retained the same rows, passed integrity checks and closed cleanly. A separate abrupt writer exit retained all 100 committed rows on reopening. This corroborates delayed checkpointing and basic recovery, not production Host byte savings or latency. The macOS Host benchmark and 392-test result in the description remain the author's measurements.

The threshold should not be interpreted as a hard bound on WAL allocation or recovery work: transaction size and readers can affect that. I did not reproduce the author's concurrent Host benchmark or measure physical storage writes.

This head merges without conflicts into current rust-preview 6fd77053. CI 42448490923 fails in the macOS desktop's first text-entry case (observed: Null, 67.497s); the earlier base run 42447608116 fails the same case before this tuning change. I have not attributed that existing failure to this PR, and this is not an all-green CI result.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

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
@YongGoose
YongGoose force-pushed the perf/event-log-wal-checkpoint branch from 3e24b44 to a8ac3c9 Compare November 22, 2026 09:17
@YongGoose YongGoose changed the title perf(event-log): checkpoint the WAL every 10,000 pages perf(event-log): checkpoint the WAL every 4,000 pages Nov 22, 2026
@M4n5ter
M4n5ter deleted the branch apache:rust-preview November 23, 2026 00:07
@M4n5ter M4n5ter closed this Nov 23, 2026
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.

3 participants