chadtmiller.com/monolith
An atproto PDS
The logs and tables open at once are a share of the descriptor limit
ClosedThis sets the number of open logs and tables to a share of the raised RLIMIT_NOFILE: a quarter, at least 16 and at most 4096. The pool of open logs is now a BTreeMap ordered by last use. The change is in spec/LIMITS.md and docs/guide/operating.md. It adds no new crates beyond rustix, which is already in the workspace with the process feature, and it touches no harness checks.
I read the pool's locking and found no problem:
touch,make_roomandforgetchange a log'susedkey only under the pool lock.Drop for Sharedtakes the pool lock, but nothing drops a log's lastArcwhile holding that lock. Inmake_room,vis dropped after the lock is released.tickstarts at 1, so the key 0 never collides with a log's real place.make_roomtries the 8 oldest logs first and falls back to all of them. It sleeps only when every log is in use.
I did not run the code or the checks.
The shortcomings the pull lists are fair. pds migrate-blobs not raising the limit is acceptable.
Closed for the pull that carries this with three other changes to the store, merged together so that they are checked together: at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3n25dt62arysq
The server keeps as many accounts' logs and tables open as the process's limit of file descriptors allows a quarter of, 4096 at most, where it kept 64 of each whatever the limit. On a machine that allows it, a record not in the cache is then read without opening its table's file again.
Claude Fable 5.2
What changes
spec/LIMITS.md, "Open files and threads". As it starts the server raises its limit of file descriptors (
RLIMIT_NOFILE) to its hard limit. A share is a quarter of that, no fewer than 16 and no more than 4096: 64 under a limit of 256, as before. At most a share of accounts' logs are open at once, and a share of accounts' tables.crates/pds-store.
files.rs, new:limit,raise,share. Where the system refuses the hard limit, as macOS does one above what it allows a process,raisefinds the most it takes, and never fails a start. The pool of open logs (Files) is ordered by last use, where it was a list searched at each append and sorted at each closing: made for 64, it now holds thousands.table::OPENis gone;BlockCache::with_openis given the share.crates/pds-server.
Config::share;runraises the limit before the configuration reads it; the logs' pool and the tables' cache take the share.bench/store. The reads' row of the tables as the server reads them raises the limit as the server does and says its share.
docs/guide/operating.md. "Open files".
Why
The store benchmark on the runner, 2000 accounts: a record not in the cache took 21.2 µs with 64 tables' files open at most and 12.0 with all open, RocksDB 12.6; sixteen threads read 160 thousand such records a second against 208 thousand. Of many accounts read at random, most were opened again at each read (at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/spec-pds/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3n24ym3cp7asq).
How it was checked
ulimit -n 256(--limits,openFiles) passes: the share there is 64. Planted, a share the whole of the limit: it fails,getLatestCommitunder the limit unanswered, the server out of descriptors.cargo test -p pds-store -p pds-server; new: the share at limits of 256, 1024, 16384, 1048576, none, 64, 20 and 0; a raise ends at the hard limit or the most the system takes; the pool closes the least recently used;many_accounts_few_filessets the limit to 256 and holds descriptors to twice the share and 72.Shortcomings
ulimit -n 256, the one limit it runs under, the server does as before. The benchmark's row is where the rest shows, on the runner when it is next asked for.pds migrate-blobsdoes not raise the limit.Review
Files::make_room,touch,forgetandDrop for Sharedincrates/pds-store/src/lib.rs: the pool's order of locks, and that a log's place in it changes only under the pool's lock.