~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Scale: memory bounded by a cache, start time independent of the accounts, repositories and the firehose streamed from disk

Closed
Closed chadtmiller.com asked to merge into lifegaps-s from chadtmiller.com/monolith:final

The server scales to any size on one machine: memory is bounded by a cache, not by the data, and start time doesn't grow with the number of accounts.

Spec (STORE.md, scale rules; observable, storage-agnostic)

  • Memory: RSS at any moment is at most a base, plus PDS_CACHE_BYTES (default 256 MiB), plus 4 KiB per account. It doesn't grow with idle accounts or repository size.
  • Start: within twice an empty start, plus 250 ms, whatever the number of accounts or amount of data.
  • Cold account: an account's first request after a start is at most 1 s slower than its next.
  • Streaming: getRepo, firehose replay and listBlobs are read from disk as they are sent.

Server

  • Lazy, evictable accounts: an account's store loads on first use and is let go, least recently used, past the cache budget or when idle. A start reads only the service log.
  • Checkpoints as sorted tables with a sparse index and bloom filter, read through a shared block cache. Compaction is a streaming merge.
  • An incremental MST: a commit rewrites only the paths it touches. It is property-tested against a full rebuild over random batches, and the atproto vectors still pass.
  • The firehose from disk: a bounded live tail in memory, and replay read from the accounts' tables and logs.
  • Allocator: jemalloc, built to keep no freed pages, so RSS follows what is in use on macOS and Linux. Huge pages are off on Linux (through rustix). sha2's asm is on, since software SHA-256 dominated cold loads on aarch64.
  • Write path: the frame log stays the commit point, with every DURABILITY.md guarantee and its byte-cut tests.

Bugs the later steps found, fixed with tests:

  • firehose replay with many cold accounts;
  • FutureCursor after a restart (seqs are reserved ahead);
  • an upload as a cold account's first request;
  • reserved seqs miscounted as events let go.

Measured (--scale, 16 MiB cache)

macOSBoundLinuxBound
Start, 2000 accounts160 ms312 ms151 ms302 ms
Memory just started, 2000 accounts19.0 MiB28.8 MiB22.9 MiB33.6 MiB
Large-repository write50.0 MiB68.8 MiB53.4 MiB73.6 MiB
getRepo of 64 MiB27.7 MiB68.8 MiB31.7 MiB73.6 MiB
Firehose replay from 041.7 MiB68.8 MiB45.7 MiB73.6 MiB

Harness: --scale measures RSS and start time over 100, then 2000 accounts and a 64 MiB repository. It runs in the perf suite, alone, since it times the server.

Checked: the code gates (in rust:1.98), cargo test --workspace, gates.mjs perf (--scale and perf), --store, plain seed 1, crash seed 21 with --firehose, --lifecycle, the other gate runs on the scale branch, and --scale on Linux.

🤖 Generated with Claude Code

Stacked on the lifecycle pull: this branch is the scale work merged with it. The one combining conflict was in lifecycle.rs, where getSubjectStatus now reads a record through the store (st.record(path)), since records are no longer all in memory.

chadtmiller.com added 22 commits
Approved

This pull makes memory depend on a cache and start time not depend on the number of accounts. It does that with lazy, evictable accounts, sorted-table checkpoints, an incremental MST, a firehose and getRepo streamed from disk, and jemalloc. The only new crates are tikv-jemallocator, plus rustix on Linux, which the workspace already had. Neither is an atproto or MCP crate.

I read these in full:

  • Cargo.toml, .cargo/config.toml, crates/pds/Cargo.toml and crates/pds/src/main.rs
  • README.md, spec/PDS.md and spec/STORE.md
  • harness/checks/scale.mjs, harness/compare.mjs, harness/gates.mjs and the harness/lib changes

What I found:

  • Spec and README: STORE.md states the new behaviour in observable terms: the PDS_CACHE_BYTES variable, the memory bound, the cold-account bound, the start bound and streaming. It also describes the --scale check. The README says what is built and how it is checked, not how it was built.
  • Harness: --scale is a new check, not a loosened one. It states what it compares: RSS, sampled every 20 ms, against base + 32 MiB + cache + 4 KiB per account; start time against twice the empty start + 250 ms; and the records and events it wrote against what comes back. The start bound in STORE.md is now stricter than the old one, since it no longer allows growth with accounts. It is checked at 100 and 2000 accounts.
  • Perf suite: gates.mjs runs the scale check alone in the perf suite, which is right for a timing check.

I did not read the Rust diff, about 13,000 lines, so I make no claim about the following. If you want a second round, point me at the parts that matter most.

  • Rust code: the pds-repo MST, pds-store tables and generations, the pds-server cache, checkpoint, log, events, blobs, sync and lifecycle code, and their tests.
  • Server code and the reference PDS: I checked nothing against the reference PDS's or an SDK's source.
  • Durability: I did not confirm that the DURABILITY.md guarantees still hold.
  • harness/conformance.yaml: the pull does not touch it.

Landed on main as part of b1f2478, the folded stack (gate speed, then the lifecycle rules, then this). Its head 3ab04f7 is in main, plus a test fix (6f62865) and the rpc refusal's aud encoding (c97fc5e). Closing, as its content is merged.