Storage: history commits p99 46-190 ms from WAL checkpoints; saves stall under big uploads #298
Closed
opened 2026-10-14 15:09:36 +00:00 by kayg
·
6 comments
No Branch/Tag specified
main
port/tasks-float-2
fix/train-1116-2
fix/train-1116-3
fix/train-1116-1
fix/flake-1134
fix/server-1182
dev
port/notes-float-3c
docs/auto-update-ig
feat/dav-transport
port/tasks-float-1
wip/mail1011-sv-order-1116
fix/flake-1179
fix/flake-1178
fix/guards-1153-fsio-split
fix/guards-1153-notes-split-we
fix/guards-1153-notes-lib
fix/guards-1153-notes-home
fix/guards-1153-ui-primitives
fix/guards-1153-primitives-e2e
fix/guards-1153-visibility-doc
feat/paper-grey-1116
fix/flake-1165
fix/flake-1119
docs/imap-766-plan-v2
fix/e2e-unique-ports
t3/paged-search-reconcile-final
wip/mail1011-final-1115
docs/tasks-float-port
perf/editor-first-paint-1c
feat/imap-notes-fetch
feat/imap-notes-projection
feat/imap-notes-readonly
feat/imap-notes-auth
feat/imap-notes-server-foundation
wip/mail1011-txn-ownvocab-1115
wip/mail1011-txn-novocab-1115
perf/p1117-final-harness
perf/single-shot-repeats
port/tasks-matrix
wip/mail1011-txn-1115
fix/static-gates-1155
feat/files-s1-identity-r7
fix/files-r7-idle-loop
fix/daily-train-1152
port/notes-float
fix/editor-tables-test-types
port/notes-float-listscript
feat/tasks-actions
port/notes-float-phone-preload
perf/sound-comparator
port/notes-float-listscroll
port/notes-float-budgets
port/notes-float-suite-fix-b
port/notes-float-sidebar-fix
port/notes-float-trim
port/notes-float-3-lists
fix/attachments-meta-capability
docs/carddav-writes-v2-plan
feat/contacts-companion-pure
issue/carddav-read-perf-fix-r2
issue/carddav-read-r2
port/notes-float-devsync2
review/calendar-2
review/switcher-a-pills
port/notes-float-switcher-a
port/port-tables-2
review/switcher-ends
wip/whiteboard-s1-1114
port/port-tables
wip/mail1011-perfneutral
review/photo-tint
port/notes-float-shell
wip/local/collections-db
wip/local/mail-p1
wip/local/cold-growth-on-tiering
wip/local/tiering-v3-s1
wip/local/wal1051-cap
wip/local/tiering-v3-s1-resume
wip/local/index-position-startup-scan
port/notes-float-flat
port/notes-float-promote
wip/handover/mail1011-candidate
wip/handover/files-s1-candidate
port/notes-float-shell-only
port/notes-float-perf
feat/whiteboard-s1
feat/tiering-v5
fix/app-switch-hitch
wip/local/files-s1-dev-v4-final
feat/files-s1-dev-v4
fix/c2-glass-shared
feat/flat-lists
wip/handover/whiteboard-s1-resume
wip/att-lazy-861
feat/switcher-browse
wip/att-lazy-860
feat/tasks-float
recovered/flat-backup-candidate
perf/stalls-1054-kc
land/ai-toolbar
feat/collections-db
feat/collections-db-fixes
codex/mail-1011-redesign-20261111
fix/ai-toolbar
backup/macos-vm/st3-head
perf/trim-candidate-phonestack
feat/switcher-three
fix/1051-index-idle-checkpoint
perf/stalls-1054-kb
perf/stalls-1054-k
perf/stalls-1054-r3
fix/c2-contrast-tail
perf/stalls-1054-r3-preview
feat/collections-before
feat/tiering-v4
fix/timelog-caret
wip/local/tasks-actions
docs/tasks-writes-v2-plan
st3-r3
feat/pass8
review/calendar-2-before-1111
wip/tiering-v3-cold4
perf/stalls-1054-r2
fix/suite-A4
fix/suite-A5-probe
fix/suite-A6
fix/suite-A3
fix/suite-A2
fix/suite-A5
fix/suite-A1
wip/local/attachments-861-fix
feat/contrast
wip/local/ports-861
storage/wal-checkpoint-off-save-1051
wip/local/mail-1011-reconcile-20261110
feat/style-sheet-fixes
feat/money-round
perf/stalls-1054
wip/tiering-v3-cold5
t3/mail-1011-liveness
feat/iphone-fixes
feat/notes-approve
wip/local/shrow-work
feat/files-s1-identity
feat/quickfix
wip/tiering-v3-cold
wip/local/shared-row-swipes
backup/macos-vm/pfx-B
backup/macos-vm/pfx-C
backup/macos-vm/pfx-D
feat/contrast-r1
feat/tiering-v3-s2-tags
feat/folder-drop
t3/photos-s1
feat/tiering-v3-s1-namespace
wip/local/photos-s1
t3/photos-plan-slice-one
recovered/backup/p1b-61505
t3/paged-search-reconcile
t3/smooth-pane-transitions
t3/index-position-startup-scan
fix/private-staging-759b-r2
backup/macos-vm/hk/hk1009/pr877
backup/macos-vm/hk/hk1009/pr878
docs/undo-block-ids-plan
fix/undo-768
backup/macos-vm/hk/hk1009/pr875
backup/macos-vm/hk/hk1009/pr904
proto/block-identity-v7d
backup/macos-vm/hk/hk1009/pr846
backup/macos-vm/hk/hk1009/pr860
backup/macos-vm/hk/hk1009/pr861
backup/macos-vm/hk/hk1009/pr849
backup/macos-vm/hk/hk1009/pr848
backup/macos-vm/hk/hk1009/pr853
backup/macos-vm/hk/hk1009/pr957
backup/macos-vm/hk/hk1009/pr893
backup/macos-vm/hk/hk1009/pr889
backup/macos-vm/hk/hk1009/pr902
docs/imap-notes-plan
docs/quota-plan-2
fix/parallel-test-flakes
docs/calendar-backend-v2-plan
feat/calendar-ical-converter
backup/macos-vm/hk/hk1009/pr808
docs/contacts-import-v2-plan
issue/610-pm-midnight
feat/calendar-v2-s1-containment
backup/macos-vm/hk/hk1009/pr854
backup/macos-vm/hk/hk1009/pr845
backup/macos-vm/hk/hk1009/pr917
docs/dav-recorder-v2-plan
plan/previews-865
plan/save-log-durable-entry
backup/macos-vm/hk/hk1009/pr934
fix/e2e-data-on-ram
backup/macos-vm/hk/hk1009/pr888
feat/appwindow3
feat/appwindow2
feat/appwindow
feat/money-p1
feat/keys-sheet
review/calendar-2-themes
feat/smooth-cursor
fix/float-style
review/calendar-2-float
release/2026-11-06-hotfix
archive/port/rows-drop-code
archive/port/rows-actions
archive/port/rows
scratch/tasks-894-ui-gates
review/calendar-2-night-wip
recovered/flaky/toast-reduced
release/2026-11-05
archive/flaky/rows-drop-fixed
archive/flaky/rows-actions
archive/flaky/rows
sim/bm15-final
sim/bm15-bis-932
sim/bm15-bis-909
sim/bm15
sim/bm15-bis-887
perf/tiering-option-b
fix/sw-lazy-precache
archive/plan/save-log-durable-entry
mock/money-fix2
archive/fix/e2e-data-on-ram
mock/appearance-all
mock/pill-press
mock/pill-press-mac
backup/macos-vm/appearance-after
mock/auto-swipes
mock/mail-actions
backup/macos-vm/mock/mail-actions
mock/money-static
archive/review/standards-917
perf/tiering-761-fix
mock/type-audit
mock/third-pane
feat/contacts-import-v2-s1
perf/executor-hot-path
archive/port/hidden-blocks
archive/port/devices
scratch/executor-on-894
scratch/executor-spans2
scratch/executor-spans
archive/port/rows-drop
feat/tiering-761-d-scale
feat/tiering-761-c-index
feat/tiering-761-b-reader
archive/review/sharing-pr3-review-9fec3d1f
perf/ports-lazy-budgets
feat/tiering-761-a-migration
archive/review/sharing-pr3-review
archive/review/sharing-pr3-review-code
archive/plan/previews-865
archive/port/port-attachments-3
archive/port/contacts-merge
fix/motion-audit-859
fix/motion-audit-859-mac
archive/port/port-pickers
archive/port/port-tables-2
archive/port/port-tables
recovered/local/sharing-s1-pr2-room-snapshot-candidate
archive/fix/parallel-test-flakes-code-minipc01
docs/imap-766-readonly-slice
feat/dav-recorder-v3
research/788-diagnosis
archive/fix/parallel-test-flakes
archive/perf/pr792-cold-index-edit
docs/sharing-slice-1
recovered/feat/dav-recorder-v2
recovered/feat/dav-recorder-v2-edd7bbb
spike/imap-766-s0-cases
archive/fix/undo-768
recovered/feat/dav-recorder
recovered/feat/dav-recorder-901acd4
feat/contacts-import
perf/cold-growth-on-764
perf/cold-growth-on-tiering
recovered/feat/tasks-set-status
feat/tasks-move-reorder
feat/tasks-delete-promote-duplicate
feat/carddav-writes
perf/quota-on-tiering
perf/quota-simple
perf/cold-growth-on-quota-stack
recovered/perf/cold-growth-on-tiering
feat/calendar-identity
feat/calendar-event-parser
feat/calendar-props-maps
port/glass-when-ring
recovered/feat/tiering-761-s1-wip-8132a84
recovered/feat/tiering-761-s1-wip-9da4094
recovered/feat/tiering-761-s1-wip-724512c
recovered/feat/tiering-761-s1-wip-66e667e
recovered/feat/tiering-761-s1
wip/6by32-01-tier-761-s1-pause-20261030
spike/imap-766-s0
wip/6by32-02-calternal-pause-20261030
wip/8by64-01-review-688-pause-20261030
wip/6by32-01-verify-744-pause-20261030
wip/6by32-01-verify-742-pause-20261030
fix/private-staging-759b
wip/6by32-01-review-748-pause-20261030
wip/6by32-01-review-733c-pause-20261030
wip/6by32-01-review-733b-pause-20261030
review/calendar-month
wip/local/bm15-trash
plan/759b-staging
review/767b-tests
review/preview-2026-10-29
docs/tiering-731-plan
wip/c6b02-review-733d
wip/c6b02-bm1-full-a
docs/deploy-plan
fix/storage-owner-liveness-642
fix/storage-fix-7
feat/tiering-731
wip/tiering-731-first-attempt
perf/idle-honest-2
fix/storage-private-tmp-642-dev
fix/storage-exact-file-quarantine-642
perf/one-flush-save
review/calendar-static
review/indexing-ring
review/when-field-2
proto/block-identity-2-review
proto/block-identity-review
review/when-field
issue/tasks-create-ids
issue/tasks-create
review/combined
review/task-polish
review/top-buttons
review/q1-q5
archive/integ325-293
archive/integ325-ci
issue/calendar-adr
archive/old/train/2026-10-23bk2
archive/old/train/2026-10-23bk
issue/469-mockup-9a
issue/smart-tasks-mockup
issue/469-menus
issue/652-signout-flake
issue/652-history-fix7
issue/652-history-fix6
archive/old/issue/spring-check-perf
issue/spring-check-perf
issue/659-rename-fast
archive/old/train/2026-10-21ar
issue/search-hardening-3
issue/652-history-fix5
issue/660-port-sheets-glass
issue/652-history-fix4
issue/652-history-fix3
issue/652-history-fix2
issue/652-history-flake
train/2026-10-21an
issue/settings-admin-port
issue/search-port
train/2026-10-20am
issue/storage-split-fix2
issue/storage-split
archive/old/issue/folder-ids-fix
train/2026-10-20al
archive/old/issue/folder-ids
train/2026-10-20ak
issue/tables-mockup
train/2026-10-19aj
train/2026-10-19ai
issue/469-merge-fixes
issue/sidebar-band
archive/old/issue/608-settings-spec
train/2026-10-19ah
issue/swipe-offscreen
train/2026-10-19ag
archive/old/issue/590-nlp-adr
archive/old/issue/587-event-after-write-2
train/2026-10-19af
archive/old/issue/587-event-after-write
issue/469-pill-room-c
issue/469-pill-room
train/2026-10-19ae
issue/469-narrow-handle
issue/397-ios-swipe-2
issue/469-desk-fixes
archive/old/issue/auto-update-adr
issue/469-filter-gap
issue/469-port-1b
issue/442-opacity-flake
issue/327-web-fast-3
archive/old/issue/469-port-1
issue/469-port-1
issue/327-web-fast-2
archive/old/issue/327-web-fast
archive/old/issue/425-stt-bench-vq1
archive/old/issue/445-no-bleed
archive/old/issue/400-swipe-mockup-2
issue/426-client-review
issue/426-client-2
issue/426-client
archive/old/issue/476-safe-area-lab
archive/old/issue/445-top-light
issue/471-blocks-mockup
archive/old/issue/448-links-app-2
archive/old/issue/448-links-app
archive/old/issue/398-cold-links
issue/434-442-small-2
issue/434-442-small
archive/old/issue/398-unload
archive/old/issue/445-bottom-band
issue/445-bottom-band
issue/351-rem-3
issue/351-rem-2
issue/351-rem
archive/old/issue/327-first-note
issue/395-width-phone
archive/old/issue/327-typing
issue/396-ios-edges
issue/397-ios-swipe
archive/old/issue/327-notes-index
issue/345-347-contrast-empty-2
archive/old/issue/44-arenas
issue/44-arenas
archive/integ325
archive/old/issue/327-perf-harness
archive/old/issue/44-thp
issue/44-thp
archive/old/issue/285-sticky-pills
archive/old/issue/44-trim-3
issue/44-trim-3
archive/old/issue/165-cards
archive/old/issue/165-picker-2
archive/old/issue/212-multi-select
No results found.
Labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
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#298
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the #14 benchmark (#14 (comment)), on the perf VM:
synchronous=NORMAL, against a target of under 10 ms. The spikes come from WAL checkpoints.Proposed work, measured before and after on the perf VM:
wal_autocheckpoint=0, plus a backgroundPRAGMA wal_checkpoint(PASSIVE)on a timer or above a size threshold, with TRUNCATE when idle.sync_file_range/fdatasync in chunks), or at a lower IO priority (ioprio/posix_fadvise);Pass when the history-commit p99 is under 10 ms and the save p99 is under 50 ms during a 1 GB upload on NVMe.
Findings so far (perf VM, 4K XFS on the NVMe and HDD zvols)
Measured with a new
storage-bench(crates/perf) that drives the real code:History::appendwith 4 readers going (history), andNotes::saveincluding the change journal (save), optionally while a 1 GB file is written over and over (upload). Every row is the median of 3 runs, caches dropped before each, all underflock /root/perf-vm.lock. Raw data:/root/i298/results.jsonlon the VM.1. The disk itself has a p99 of 5 to 60 ms per flush
A raw 4 KiB
pwrite+fdatasyncloop on/mnt/z4-nvme(2000 flushes), at four points tonight:A durable history commit needs at least one flush, so a commit p99 under 10 ms is not reachable on this VM with history kept durable before "Saved" (ADR 0020): the flush alone is above it most of the night. It swings a lot with whatever else the host pool is doing.
2. The p99 spikes were not the checkpoint
I moved checkpoints off the commit path (
wal_autocheckpoint=0plus a checkpoint thread: PASSIVE every 500 ms while writing, TRUNCATE after 2 s quiet) and measured it against dev:No difference beyond noise, and worse: with writes never pausing, a separate checkpointer can never let the log start over, so the WAL grew to 83 MB in a 4000-commit run (dev stays at 4.8 MB). I dropped it. The tails come from the disk (point 1).
3. What does cost: SQLite uses
fsync, notfdatasyncThe SQLite that rusqlite bundles is built without
HAVE_FDATASYNC, so it flushes withfsync()(strace on the VM: onefsyncper commit, nofdatasync).fsyncalso writes the file's times, so each commit waits for the file system's log too. WithLIBSQLITE3_FLAGS=-DHAVE_FDATASYNC=1, locally (ext4 SSD) a history commit goes from p50 7.2 / p99 19 ms to p50 3.6 / p99 8 to 12 ms, and throughput from 122 to 245 commits/s: one flush per commit, as the raw disk. VM numbers for this follow.4. A save made four flushes in a row
Pending record (history), the temp file, the folder, the "done" record. Now the temp file is written and flushed while history records the pending save (swapped in only once that is durable), and "done" is queued without waiting (a crash keeps the pending row, which matches the file; the next start promotes it, as load.rs already does):
p50 halves; p99 stays at the disk's noise (point 1).
5. Uploads: bounded steps help, going around the cache hurts
On a ZFS volume a flush carries everything written to the volume before it, so a note save during an upload waits for the upload's data. Saves during a looping 1 GB write on the same NVMe volume:
O_DIRECT, 4 MiB steps(The 1 MiB / 256 KiB / other-disk rows also have the overlapped save, so compare their tails, not the p50; a clean same-build comparison follows.) 1 MiB steps take the save p99 from 2.2 s to about 100 ms, roughly what saves see with no upload at all; the upload drops to about 95 MB/s, still close to what gigabit brings in. Putting attachments on another volume than notes and DBs is just as good, so the deploy layout in point 4 of the issue stands.
Plan
fdatasync(build flag) +storage-bench.write_atomicand a newwrite_atomic_from).Running now: the full #44 harness (10k and 100k) dev vs all of the above, then the final same-build before/after on NVMe and HDD.
SQLite with
fdatasyncon the perf VM (#377)dev (
583c46e) vs the same tree built withLIBSQLITE3_FLAGS=-DHAVE_FDATASYNC=1, nothing else changed.storage-bench, median of 3 runs each, caches dropped before each run, under the perf lock. Raw 4 KiB flush on the NVMe volume during this round: p50 4.9 / p99 31 ms, then 4.1 / 22 ms.On XFS over a ZFS volume a lone commit costs about the same either way (the device flush dominates; the single-writer difference is within the run-to-run spread, which is large tonight). It pays off where flushes queue up: with 4 writers +48% commits/s and p99 145 → 60 ms, and a note save (several flushes in a row) p50 34 → 23 ms. On ext4 (my workstation) it halves every commit: p50 7.2 → 3.6 ms, p99 19–22 → 8–12 ms.
Also: a round of the #44 harness I ran earlier compared builds on two different dev bases, so its differences mixed in #44's own merges; I'm rerunning it on one base (dev
a305ee2: dev, dev + #298 PRs, dev + #298 PRs + #297).Correction to the earlier save numbers: the overlapped save I measured also stopped waiting for the "done" record. CI caught a real case against that (
edit_while_closed_is_merged_on_open: a save whose "done" is lost, then an outside edit while the server is down, is mistaken for an unwritten save, and text doubles). The save now waits for "done" again (3 flushes in a row instead of 4, not 2). New numbers follow; #378 is replaced by a new PR.All of #298 together on the perf VM (final build vs dev)
dev
a305ee2(+storage-bench) vs deva305ee2+ #377 (fdatasync) + #392 (overlapped save, "done" waited for) + #379 (1 MiB upload steps) + #297. Median of 3 runs each, caches dropped before every run, under the perf lock. The disk's own 4 KiB flush during this round: p50 3.7 / p99 8 ms at the start, p50 5.1 / p99 50 ms halfway.Note saves (
storage-bench save: append a line, thenNotes::save, which includes the change journal; 200 saves of 0.5 to 30 KB notes, 100 of a 300 KB note):Note saves while a 1 GB file is written over and over on the same volume:
The same-build pair isolates #379: p90 1.5 s → 93 ms, p99 2.4 s → 230 ms under a full-speed upload; saves no longer queue behind the upload. On the HDD volume the stall goes from tens of seconds to a third of a second.
History commits in this round: dev p50 7.9 / p99 31 ms (1 writer) and 15.8 / 49 (4 writers); final 9.4 / 44 and 20.7 / 80. That is the opposite of the previous round's fdatasync-only A/B (where 4 writers went 17.8 / 145 → 15.8 / 60), with the raw disk swinging from p99 8 to 50 ms within this one round. So on this VM I can't separate fdatasync's effect on a lone commit from the disk's noise; a 6-pair interleaved A/B is running now to settle it. (On ext4 it halves every commit.)
Targets: history-commit p99 < 10 ms is below what this VM's disk does for a single flush most of the night (raw p99 5 to 60 ms), so no software change gets there here; it needs a disk whose flushes are fast (a SLOG or power-loss-protected NVMe). Note-save p99 < 50 ms during an upload: not met at p99 (230 ms), but p50/p90 under a full-speed upload are now 59 / 93 ms, close to a save with no upload on this disk (p99 210 ms there too).
Next: interleaved fdatasync A/B, then the #44 harness on one base (dev
a305ee2: dev, + #298 PRs, + #298 PRs + #297).fdatasync A/B, interleaved (#377)
To get past the disk's drift between rounds: dev
a305ee2vs the same tree with onlyLIBSQLITE3_FLAGS=-DHAVE_FDATASYNC=1, 6 pairs run back to back and alternating (dev, fdatasync, fdatasync, dev, ...), caches dropped before each run, NVMe volume, 4000 history commits per run with 4 readers. Medians over the 6 runs:On this VM (XFS over a ZFS volume)
fdatasyncis about neutral: a lone commit's p50 drops by ~15%, the rest is within noise; the device flush is the cost either way. The big round-to-round swings I posted before were the disk, not the change. Where the file system's log write is a separate cost (ext4 on my workstation) it halves every commit (p50 7.2 → 3.6 ms). It's the right flag for SQLite on Linux either way and costs nothing, so #377 stays, with its claims trimmed to this.The #44 harness, one base: dev vs #298 PRs vs #298 PRs + #297
dev
a305ee2vs dev + #377 + #392 + #379 vs that + #408 (#297).calternal-perf --sizes 10k,100k --runs 3 --cold-runs 1 --idle-secs 120 --drop-caches, same harness binary for all three, run one after another under the perf lock. Reports:/root/i298/m8-{h2dev,h2no297,h2final}.{md,json}on the VM.(An earlier harness round compared builds on two different dev bases, so #44's own merges were mixed into the differences; disregard it.)
Summary
home.first_page@100000p95 (dev 70, #298 127, both 121; budget 100), whose run-to-run noise is 220 to 540 %, over the 25 % rerun threshold. It is the first read after start; nothing in these PRs touches that path.sync.save_ackp50 6.2 → 3.5 ms (10k), 8.6 → 4.7 ms (100k);storm.save_ackat 100k p50 / p95 19.8 / 40.3 → 11.3 / 26.4 ms;storm.edits_per_sat 100k 1170 → 2070.load.typing(5 chars/s for a minute, now saving every 5 s instead of once) CPU 0.73 → 0.6 % at 100k (budget 2 %), wake-ups 41 → 56 /s (not budgeted).shutdownat 100k p50 / p95 64 / 88 → 275 / 773 ms with 242 % noise (budget 1000): one slow run; worth watching.10000 notes (p50 / p95; noise is the spread of the runs' p50s)
100000 notes (p50 / p95; noise is the spread of the runs' p50s)
Closing during the 26 Oct handover cleanup: The storage tail fixes landed in dev (PRs #377, #379, #385, #392).