Storage: SQLite flushes with fdatasync, plus storage-bench (#298) #377

Closed
kayg wants to merge 0 commits from issue/298-fdatasync into dev
Owner

Part of #298 (storage latency). Small and independent; the other #298 PRs build on its bench.

What

  • .cargo/config.toml: LIBSQLITE3_FLAGS = "-DHAVE_FDATASYNC=1". The SQLite that rusqlite bundles is compiled without HAVE_FDATASYNC, so it flushes with fsync(). That also writes the file's times, so every durable commit (history, auth) waited for the file system's log as well as its data: about two flushes per commit instead of one. SQLite's own source says fdatasync() is always adequate for it. Verified with strace on the perf VM: one fsync per history commit, no fdatasync, before this.
  • deploy/Containerfile copies .cargo in, so release images get it too. CI builds from the checkout, so they do already.
  • storage-bench (crates/perf, documented in docs/perf/budgets.md): history commits (History::append with readers) and note saves (Notes::save with the change journal) timed straight against the real code on any disk, optionally while a big file is being written.

Numbers

  • Local ext4 SSD, storage-bench history (4000 commits, 4 readers): p50 7.2 → 3.6 ms, p99 19–22 → 8–12 ms, 122 → 245 commits/s. The raw disk's own 4 KiB flush is p50 3.2 / p99 6.5–8.5 ms, so a commit now costs one flush.
  • Perf VM (4K XFS on the NVMe zvol), 6 interleaved pairs (#298): about neutral. A lone commit's p50 11.5 → 9.7 ms, everything else within noise; on XFS over a ZFS volume the device flush is the cost either way.

Not changed: durability. synchronous = FULL stays where it was (history, auth); only the syscall SQLite flushes with changes.

Coordination: this changes how every SQLite database flushes (search and the note list too), which only makes their commits and checkpoints cheaper.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Part of #298 (storage latency). Small and independent; the other #298 PRs build on its bench. **What** - `.cargo/config.toml`: `LIBSQLITE3_FLAGS = "-DHAVE_FDATASYNC=1"`. The SQLite that rusqlite bundles is compiled without `HAVE_FDATASYNC`, so it flushes with `fsync()`. That also writes the file's times, so every durable commit (history, auth) waited for the file system's log as well as its data: about two flushes per commit instead of one. SQLite's own source says `fdatasync()` is always adequate for it. Verified with strace on the perf VM: one `fsync` per history commit, no `fdatasync`, before this. - `deploy/Containerfile` copies `.cargo` in, so release images get it too. CI builds from the checkout, so they do already. - `storage-bench` (crates/perf, documented in docs/perf/budgets.md): history commits (`History::append` with readers) and note saves (`Notes::save` with the change journal) timed straight against the real code on any disk, optionally while a big file is being written. **Numbers** - Local ext4 SSD, `storage-bench history` (4000 commits, 4 readers): p50 7.2 → **3.6 ms**, p99 19–22 → **8–12 ms**, 122 → **245 commits/s**. The raw disk's own 4 KiB flush is p50 3.2 / p99 6.5–8.5 ms, so a commit now costs one flush. - Perf VM (4K XFS on the NVMe zvol), 6 interleaved pairs (#298): about neutral. A lone commit's p50 11.5 → 9.7 ms, everything else within noise; on XFS over a ZFS volume the device flush is the cost either way. **Not changed**: durability. `synchronous = FULL` stays where it was (history, auth); only the syscall SQLite flushes with changes. **Coordination**: this changes how every SQLite database flushes (search and the note list too), which only makes their commits and checkpoints cheaper. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Storage: SQLite flushes with fdatasync, half the wait per commit (#298)
Some checks failed
CI / server (pull_request) Successful in 1m1s
CI / web (pull_request) Failing after 2m18s
CI / rust (pull_request) Failing after 1m52s
a7494fbdca
The SQLite that rusqlite bundles is built without HAVE_FDATASYNC, so it
flushes with fsync(), which on Linux also writes the file's times: every
durable commit (history, auth) waited for the file system's log as well
as the data. fdatasync() is all SQLite needs (its own source says so).
LIBSQLITE3_FLAGS in .cargo/config.toml turns it on for every build;
the Containerfile copies it in.

Adds storage-bench (crates/perf): history commits and note saves timed
straight against the real code on a chosen disk, with readers or a big
upload running at the same time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

CI note: the rust job's failure here is error[E0463]: can't find crate for calternal_notes, a build race in the shared /target cache (this PR changes the SQLite build flags, so libsqlite3-sys and everything above it rebuilds while other jobs use the same directory). #379 contains this same commit and its rust job passed (fmt, clippy, all tests). The web job fails on dev too.

CI note: the rust job's failure here is `error[E0463]: can't find crate for calternal_notes`, a build race in the shared `/target` cache (this PR changes the SQLite build flags, so libsqlite3-sys and everything above it rebuilds while other jobs use the same directory). #379 contains this same commit and its rust job passed (fmt, clippy, all tests). The web job fails on dev too.
kayg changed title from Storage: SQLite flushes with fdatasync, one flush per commit instead of two (#298) to Storage: SQLite flushes with fdatasync, plus storage-bench (#298) 2026-10-15 04:10:43 +00:00
Author
Owner

Landed in dev via train k (#441).

Landed in dev via train k (#441).
kayg closed this pull request 2026-10-15 14:34:25 +00:00
Some checks failed
CI / server (pull_request) Successful in 1m1s
CI / web (pull_request) Failing after 2m18s
CI / rust (pull_request) Failing after 1m52s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!377
No description provided.