Storage: big writes go to the disk in 1 MiB steps, so note saves don't wait behind uploads (#298) #379

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

Part of #298 (saves stall during big uploads). Stacked on the fdatasync PR (it needs storage-bench); merge that first, then this shows only its own commit.

What
On a ZFS volume a flush carries everything written to the volume before it, so a note save during an upload waited for the upload's data: 2 to 3 s at p99 on the perf VM. write_atomic, and the new write_atomic_from for streams (future attachments), now write big content in 1 MiB steps: each step is flushed (fdatasync) before the next is written, then dropped from the page cache (posix_fadvise(DONTNEED), so an upload doesn't push notes out of memory). A save waits behind one step at most. Small writes (≤ 1 MiB, every note) are unchanged. Backdrop uploads already go through write_atomic.

storage-bench save gets --upload paced and --upload-dir.

Numbers (perf VM, NVMe zvol, saves during a 1 GB file written over and over on the same volume, median of 3 runs):

upload written as save p50 p90 p99 upload MB/s
dev (all at once, one fsync at the end) 71.5 1597 2191 458
O_DIRECT, 4 MiB steps (tried, dropped) 446 1202 1857 466
fdatasync every 4 MiB (tried) 115 220 490 130
fdatasync every 1 MiB (this) 33 50 105 94
fdatasync every 256 KiB (tried) 27 44 103 48
dev's way, upload on the HDD volume instead 21 40 120 158

1 MiB keeps saves near their no-upload numbers; smaller steps only slow the upload. The upload still writes at about gigabit speed. Writing attachments to another volume than notes is as good, which supports the deploy layout in #298. Same build (dev a305ee2 + all #298 PRs), only the upload's way of writing changed, NVMe, median of 3 runs (#298, comment 50476): save p50 / p90 / p99 46 / 1511 / 2357 ms → 59 / 93 / 230 ms. On the HDD volume, saves during an upload go from 21 s at p50 (dev) to 215 ms.

Tests: new fsio test that big writes (3 steps and an odd tail, from bytes and from a stream, and an empty stream) arrive whole and leave no temporary file.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Part of #298 (saves stall during big uploads). **Stacked on the fdatasync PR** (it needs `storage-bench`); merge that first, then this shows only its own commit. **What** On a ZFS volume a flush carries everything written to the volume before it, so a note save during an upload waited for the upload's data: 2 to 3 s at p99 on the perf VM. `write_atomic`, and the new `write_atomic_from` for streams (future attachments), now write big content in 1 MiB steps: each step is flushed (`fdatasync`) before the next is written, then dropped from the page cache (`posix_fadvise(DONTNEED)`, so an upload doesn't push notes out of memory). A save waits behind one step at most. Small writes (≤ 1 MiB, every note) are unchanged. Backdrop uploads already go through `write_atomic`. `storage-bench save` gets `--upload paced` and `--upload-dir`. **Numbers** (perf VM, NVMe zvol, saves during a 1 GB file written over and over on the same volume, median of 3 runs): | upload written as | save p50 | p90 | p99 | upload MB/s | |---|---|---|---|---| | dev (all at once, one fsync at the end) | 71.5 | 1597 | 2191 | 458 | | `O_DIRECT`, 4 MiB steps (tried, dropped) | 446 | 1202 | 1857 | 466 | | fdatasync every 4 MiB (tried) | 115 | 220 | 490 | 130 | | **fdatasync every 1 MiB (this)** | 33 | 50 | 105 | 94 | | fdatasync every 256 KiB (tried) | 27 | 44 | 103 | 48 | | dev's way, upload on the HDD volume instead | 21 | 40 | 120 | 158 | 1 MiB keeps saves near their no-upload numbers; smaller steps only slow the upload. The upload still writes at about gigabit speed. Writing attachments to another volume than notes is as good, which supports the deploy layout in #298. Same build (dev a305ee2 + all #298 PRs), only the upload's way of writing changed, NVMe, median of 3 runs (#298, comment 50476): save p50 / p90 / p99 **46 / 1511 / 2357 ms → 59 / 93 / 230 ms**. On the HDD volume, saves during an upload go from 21 s at p50 (dev) to 215 ms. **Tests**: new fsio test that big writes (3 steps and an odd tail, from bytes and from a stream, and an empty stream) arrive whole and leave no temporary file. 🤖 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
Storage: big writes go to the disk in 1 MiB steps, so saves don't wait behind them (#298)
Some checks failed
CI / server (pull_request) Successful in 1m20s
CI / rust (pull_request) Successful in 1m38s
CI / web (pull_request) Failing after 2m11s
56adbb5377
A file written in one go (an upload) sat in memory and went to the disk
all at once; on a ZFS volume every flush carries what was written
before it, so a note save during a 1 GB upload waited 2 to 3 s. Now
write_atomic and the new write_atomic_from (for streams) flush each
1 MiB step before writing the next and drop it from the page cache. A
save waits behind at most one step.

storage-bench gets `--upload paced` and `--upload-dir`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
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:26 +00:00
Some checks failed
CI / server (pull_request) Successful in 1m20s
CI / rust (pull_request) Successful in 1m38s
CI / web (pull_request) Failing after 2m11s

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!379
No description provided.