chadtmiller.com/monolith
An atproto PDS
pds-server: a cold first use replays at most 4 MiB of an account's log
MergedThis caps an account's log at 4 MiB past its table, makes writers wait for a fold once the log is 2 MiB beyond that, and starts the next fold as one ends if it is due. It also stripes the loading lock by DID, and adds a --store step that checks a cold first getRecord reads at most 6 MiB. The spec, the code and the harness step agree, and the harness change adds a check without loosening any. I found nothing that must change.
One small docs miss: bench/store/README.md says "a log may grow to its table's size before it is compacted" near line 558 (base numbering), in the prose after the zstd table. The pull updated the same sentence at line 504 but not this one, so the README now contradicts itself.
I did not run anything. I relied on the pull's report of the gates and nightly runs.
The README holds that sentence once: this branch began before main's README grew, so its line 504 is main's 558. Merged main into the branch (no conflicts): bench/store/README.md now has it at 558, as the pull changed it, "grow to its table's size, or 4 MiB if that is less, before it is compacted", and no other.
Carried forward: the change this pull makes at a8dc9a073f78ae1dfa250d252dc0266dfe0fd6f8 is the one reviewed at 8eddbbeda213b7c5dbe294835d8037a351196b0d, so that review stands. What is new comes from its base.
After a start, an account's first request replays its whole log, and a log is folded only once it outgrows its table: with a day of events, logs of 20–25 MiB, and a first write taking 0.2 to 2 s against the spec's second. This folds an account's log before it holds 4 MiB, so a cold first use reads at most 6 MiB.
Claude Opus 5.5 · high
What changes
spec/STORE.md. "The first request to a cold account": within the second however many accounts' first requests come at once, and to answer it the server reads at most 6 MiB of the account's files besides what the request itself reads, whatever the account holds: an account's log is folded into its table before it holds 4 MiB of writes, and the events it keeps for the firehose are not read for it. "Bounds": a write waits for the compaction under way also once the log holds 2 MiB more than what folds it. "How it is checked": the
--storerun's new step.harness/checks/store.mjs. Where Linux counts a process's reads (
/proc/<pid>/io,rchar): a new account with a space of its own gets 48 records of 250 KB (a table of 12 MB or more);2 Wand a write, the settled fold, so its log begins again; at once 16 rewrites (8 MB of log); the directory settles; a SIGTERM and a start; then its firstgetRecordmust read at most 6 MiB. Its records are deleted after. Elsewhere the step is skipped and says so. The run's summary line says what it read.deleteKeytakes a key.crates/pds-server.
store::policycaps an account's log atConfig::account_cap,ACCOUNT_CAP(4 MiB), past its table (max(min(table, cap), log_floor)), as the service log's is atSERVICE_CAP.Slot::write_lockmakes a writer wait for the fold under way once the log holdsBEHIND, 2 MiB, more than that, so writes during a long fold of a large table cannot leave a large log.directory's one loading lock is 64, by DID, so different accounts' first loads do not wait for each other's reads; two loads of one account still exclude each other. New testcache::tests::a_first_load_replays_a_capped_log, with a cap of 32 KiB: a data directory of 1.7 MB, within what the gates' /dev/shm holds.crates/pds-store. A fold that ends with its log already past the policy's limit starts the next at once (
Shared::again, the sametriggeran append runs, under the log's lock), where before only the next append did: writes that came while a fold ran could leave a log past the cap at rest. New testgenerations::tests::compacts_again_as_one_ends_if_due(a fold held open, appends past the limit, released: the next fold begins with no append);writes_go_on_while_it_compactsnow expects that second fold.BlockCache::read_bytes, the table bytes read from disk, for the capped-log test.bench/store/README.md. A log grows to its table's size, or 4 MiB if that is less.
Why
On spec-pds.chadtmiller.com, after a kill and after a clean deploy, each account's first write took p50 210–224 ms, p90 0.8–1.0 s, worst 1.2 and 2.2 s; later writes 6 ms. Measured there after a clean restart, its files out of the page cache, one first request at a time: the bytes read were the account's log (0.6 MiB log, 42 MiB table: 0.9 MB read, 71 ms; 21–25 MiB logs beside 23–27 MiB tables: 21–27 MB read, 305–381 ms). 50 accounts at once read about 1 GB. A first diagnosis, that the first load walks the events section, was measured too: it reads about 19 bytes an event, too little to matter, and is left as it was.
Capping the log costs table rewrites: a 25 MiB table is written again for each 4 MiB of log instead of each 25 MiB. In the test, 16 MB of log after a 21 MB table wrote about 115 MB of table (7x, against about 2x), with no slower writes, as folds run on their own thread.
How it was checked
The step, run on Linux here (the harness in a node container, each server's binary built by the Dockerfile): the server as it was, a log of 8.1 MB beside a table of 12.3 MB and the first
getRecordreading 9,104,933 bytes, failing; with this change, a log of 3.5 MB and 4,557,530 bytes read, and the whole--storerun passing. The same server as it was run with the cap removed is the planted bug. The unit test fails with the cap removed ("a log of 314835 bytes past a table of 336699").On the runner, before the step had an account of its own, it read 0.5 MB of the server as it was and passed: the run's accounts are loaded while the server starts, as they have writes to a space no directory knows, so their first request reads none of their log. That is why the step makes its own.
just nightlyhere: on 3b443a2, the six crash runs of 1000 steps,perf.mjsand--scale, all passing; on 23d3b4d, after a fold that ends begins the next, the crash runs again (seed 22 with--firehosefailed once on the reference's owncreateSession, and passed run again alone) and the perf group. The gates pass on 8eddbbe, the store run's step reading 4,559,552 bytes of at most 6,291,456.Shortcomings
What a start reads of accounts it loads before it answers, as the run's accounts with writes to an unknown space, is the start's, held by the starting bound, not this one.
With the step in the store run, three runs of the gates of four lost one
getLatestCommitspan (spec/OPERATIONS.md, "Spans"), never seen here on Linux or macOS in the same run. The step's 250 KB writes load the harness, whose receiver has 3 s to answer an export (OTEL_BSP_EXPORT_TIMEOUT); that it is an export timed out is a guess. The spans check now says when such a request ended among the server's lives, so the next loss shows where.The cap makes large tables rewritten more often; the store benchmark measures pds-store alone and does not show it.
Review
The design:
store::policy's cap andSlot::write_lock's wait (crates/pds-server/src/store.rs,cache.rs), the fold begun as one ends (crates/pds-store/src/generations.rs,Shared::again), and the striped loading lock indirectory.rs.