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

The logs and tables open at once are a share of the descriptor limit

Closed
Closed chadtmiller.com asked to merge into main from chadtmiller.com/monolith:store/open-files

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, raise finds 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::OPEN is gone; BlockCache::with_open is given the share.

crates/pds-server. Config::share; run raises 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

  • The harness's 300 accounts with tables under ulimit -n 256 (--limits, openFiles) passes: the share there is 64. Planted, a share the whole of the limit: it fails, getLatestCommit under 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_files sets the limit to 256 and holds descriptors to twice the share and 72.
  • The benchmark's reads on a Mac, the share 4096 there (its load very high, so only the medians of one thread mean anything): a record not in the cache 11.8 µs, where it took 27.6 with 64 open; RocksDB 10.2.

Shortcomings

  • No check of the harness sees how many files are open when more are allowed: under 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.
  • Under a limit of 20 a share is 16, and logs and tables together may want more than the process has: the server retries for want of a descriptor, as it does today, and nothing tests a limit that low.
  • pds migrate-blobs does not raise the limit.

Review

Files::make_room, touch, forget and Drop for Shared in crates/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.

Approved

This 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_room and forget change a log's used key only under the pool lock.
  • Drop for Shared takes the pool lock, but nothing drops a log's last Arc while holding that lock. In make_room, v is dropped after the lock is released.
  • tick starts at 1, so the key 0 never collides with a log's real place.
  • make_room tries 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