chadtmiller.com/monolith
An atproto PDS
0
0
bench: the store's logs beside SQLite, and the service log by accounts
.knotless/workflows/store-bench.ymlnew+29−0
| @@ -0,0 +1,29 @@ | ||
# The store benchmark (bench/store/README.md), as `just store-bench` runs | ||
# it: the server's logs beside SQLite under the same commits, a log | ||
# replayed, and the server's start and memory by the number of accounts in | ||
# its service log. Its log is the tables, for bench/store/RESULTS.md. On a | ||
# pull that changes the benchmark, so that what it measures on the runner is | ||
# read with the change; and on main when the owner asks. It fails only if | ||
# the benchmark cannot build or run, never for a number. | ||
# | ||
# Node, the pages' packages and both builds are kept between runs. | ||
image: rust:1.98 | ||
runners: [runner.knotless.dev] | ||
on: | ||
pull: | ||
base: [refs/heads/main] | ||
paths: [bench/store/**, .knotless/workflows/store-bench.yml] | ||
asked: {refs: [refs/heads/main]} | ||
cache: [target, bench/store/target, /usr/local/cargo/registry, /usr/local/rustup, /opt/node, web/node_modules] | ||
steps: | ||
- uses: chadtmiller.com/steps/node@1 | ||
with: {version: 24.22.1} | ||
- uses: chadtmiller.com/steps/npm-ci@1 | ||
with: {dir: web} | ||
# The pages, which pds-server embeds. | ||
- name: web | ||
run: cd web && PATH=/opt/node/bin:$PATH npm run build | ||
- name: build | ||
run: cargo build --release -p pds | ||
- name: store-bench | ||
run: PATH=/opt/node/bin:$PATH bench/store/run.sh | ||
bench/store/src/main.rsnew+423−0
423 lines changed: not loaded until asked for.
bench/store/Cargo.locknew+365−0
| @@ -0,0 +1,365 @@ | ||
# This file is automatically @generated by Cargo. | ||
# It is not intended for manual editing. | ||
version = 4 | ||
| ||
[[package]] | ||
name = "ahash" | ||
version = "0.8.12" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" | ||
dependencies = [ | ||
"cfg-if", | ||
"once_cell", | ||
"version_check", | ||
"zerocopy", | ||
] | ||
| ||
[[package]] | ||
name = "bitflags" | ||
version = "2.13.2" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" | ||
| ||
[[package]] | ||
name = "block-buffer" | ||
version = "0.10.4" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | ||
dependencies = [ | ||
"generic-array", | ||
] | ||
| ||
[[package]] | ||
name = "cc" | ||
version = "1.11.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" | ||
dependencies = [ | ||
"find-msvc-tools", | ||
"shlex", | ||
] | ||
| ||
[[package]] | ||
name = "cfg-if" | ||
version = "1.0.5" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | ||
| ||
[[package]] | ||
name = "cpufeatures" | ||
version = "0.2.17" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | ||
dependencies = [ | ||
"libc", | ||
] | ||
| ||
[[package]] | ||
name = "crypto-common" | ||
version = "0.1.7" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | ||
dependencies = [ | ||
"generic-array", | ||
"typenum", | ||
] | ||
| ||
[[package]] | ||
name = "digest" | ||
version = "0.10.7" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | ||
dependencies = [ | ||
"block-buffer", | ||
"crypto-common", | ||
] | ||
| ||
[[package]] | ||
name = "fallible-iterator" | ||
version = "0.3.0" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" | ||
| ||
[[package]] | ||
name = "fallible-streaming-iterator" | ||
version = "0.1.9" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" | ||
| ||
[[package]] | ||
name = "find-msvc-tools" | ||
version = "0.1.15" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" | ||
| ||
[[package]] | ||
name = "generic-array" | ||
version = "0.14.7" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | ||
dependencies = [ | ||
"typenum", | ||
"version_check", | ||
] | ||
| ||
[[package]] | ||
name = "hashbrown" | ||
version = "0.14.5" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" | ||
dependencies = [ | ||
"ahash", | ||
] | ||
| ||
[[package]] | ||
name = "hashlink" | ||
version = "0.9.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" | ||
dependencies = [ | ||
"hashbrown", | ||
] | ||
| ||
[[package]] | ||
name = "hex" | ||
version = "0.4.3" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" | ||
| ||
[[package]] | ||
name = "itoa" | ||
version = "1.0.19" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" | ||
| ||
[[package]] | ||
name = "libc" | ||
version = "0.2.191" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | ||
| ||
[[package]] | ||
name = "libsqlite3-sys" | ||
version = "0.30.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" | ||
dependencies = [ | ||
"cc", | ||
"pkg-config", | ||
"vcpkg", | ||
] | ||
| ||
[[package]] | ||
name = "memchr" | ||
version = "2.8.3" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" | ||
| ||
[[package]] | ||
name = "once_cell" | ||
version = "1.21.4" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" | ||
| ||
[[package]] | ||
name = "pds-store" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"serde_json", | ||
"sha2", | ||
] | ||
| ||
[[package]] | ||
name = "pkg-config" | ||
version = "0.3.34" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" | ||
| ||
[[package]] | ||
name = "proc-macro2" | ||
version = "1.0.107" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" | ||
dependencies = [ | ||
"unicode-ident", | ||
] | ||
| ||
[[package]] | ||
name = "quote" | ||
version = "1.0.47" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" | ||
dependencies = [ | ||
"proc-macro2", | ||
] | ||
| ||
[[package]] | ||
name = "rusqlite" | ||
version = "0.32.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e" | ||
dependencies = [ | ||
"bitflags", | ||
"fallible-iterator", | ||
"fallible-streaming-iterator", | ||
"hashlink", | ||
"libsqlite3-sys", | ||
"smallvec", | ||
] | ||
| ||
[[package]] | ||
name = "serde" | ||
version = "1.0.229" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" | ||
dependencies = [ | ||
"serde_core", | ||
] | ||
| ||
[[package]] | ||
name = "serde_core" | ||
version = "1.0.229" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" | ||
dependencies = [ | ||
"serde_derive", | ||
] | ||
| ||
[[package]] | ||
name = "serde_derive" | ||
version = "1.0.229" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" | ||
dependencies = [ | ||
"proc-macro2", | ||
"quote", | ||
"syn 3.0.10", | ||
] | ||
| ||
[[package]] | ||
name = "serde_json" | ||
version = "1.0.154" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" | ||
dependencies = [ | ||
"itoa", | ||
"memchr", | ||
"serde", | ||
"serde_core", | ||
"zmij", | ||
] | ||
| ||
[[package]] | ||
name = "sha2" | ||
version = "0.10.9" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | ||
dependencies = [ | ||
"cfg-if", | ||
"cpufeatures", | ||
"digest", | ||
"sha2-asm", | ||
] | ||
| ||
[[package]] | ||
name = "sha2-asm" | ||
version = "0.6.4" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "b845214d6175804686b2bd482bcffe96651bb2d1200742b712003504a2dac1ab" | ||
dependencies = [ | ||
"cc", | ||
] | ||
| ||
[[package]] | ||
name = "shlex" | ||
version = "2.0.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" | ||
| ||
[[package]] | ||
name = "smallvec" | ||
version = "1.16.5" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" | ||
| ||
[[package]] | ||
name = "store-bench" | ||
version = "0.0.0" | ||
dependencies = [ | ||
"hex", | ||
"pds-store", | ||
"rusqlite", | ||
"serde_json", | ||
] | ||
| ||
[[package]] | ||
name = "syn" | ||
version = "2.0.119" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" | ||
dependencies = [ | ||
"proc-macro2", | ||
"quote", | ||
"unicode-ident", | ||
] | ||
| ||
[[package]] | ||
name = "syn" | ||
version = "3.0.10" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" | ||
dependencies = [ | ||
"proc-macro2", | ||
"quote", | ||
"unicode-ident", | ||
] | ||
| ||
[[package]] | ||
name = "typenum" | ||
version = "1.20.1" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | ||
| ||
[[package]] | ||
name = "unicode-ident" | ||
version = "1.0.27" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" | ||
| ||
[[package]] | ||
name = "vcpkg" | ||
version = "0.2.15" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" | ||
| ||
[[package]] | ||
name = "version_check" | ||
version = "0.9.5" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | ||
| ||
[[package]] | ||
name = "zerocopy" | ||
version = "0.8.63" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" | ||
dependencies = [ | ||
"zerocopy-derive", | ||
] | ||
| ||
[[package]] | ||
name = "zerocopy-derive" | ||
version = "0.8.63" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" | ||
dependencies = [ | ||
"proc-macro2", | ||
"quote", | ||
"syn 2.0.119", | ||
] | ||
| ||
[[package]] | ||
name = "zmij" | ||
version = "1.0.23" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" | ||
bench/store/Cargo.tomlnew+16−0
| @@ -0,0 +1,16 @@ | ||
# The store benchmark (README.md): a workspace of its own, so that SQLite, | ||
# which it measures the server's log beside, is no dependency of the server, | ||
# and no gate builds it. | ||
[package] | ||
name = "store-bench" | ||
version = "0.0.0" | ||
edition = "2024" | ||
publish = false | ||
| ||
[dependencies] | ||
pds-store = { path = "../../crates/pds-store" } | ||
rusqlite = { version = "0.32", features = ["bundled"] } | ||
serde_json = "1" | ||
hex = "0.4" | ||
| ||
[workspace] | ||
bench/store/README.mdnew+95−0
| @@ -0,0 +1,95 @@ | ||
# The store benchmark | ||
| ||
What the way the server keeps its data costs, measured apart from the rest | ||
of the server: its logs (`crates/pds-store`) beside SQLite under the same | ||
commits, how fast a log is replayed, and how the server's start and memory | ||
follow the number of accounts in its service log. The PDS benchmark | ||
([`../README.md`](../README.md)) measures whole servers, each with its own | ||
durability, in its own language and some in a container; this holds | ||
everything but the layout the same. The last results are in | ||
[`RESULTS.md`](RESULTS.md). | ||
| ||
It is a workspace of its own: SQLite is a dependency of the benchmark, not | ||
of the server, and no gate builds it. | ||
| ||
## Running it | ||
| ||
```sh | ||
just store-bench # builds the server, then bench/store/run.sh | ||
just store-bench 10000 200000 # other counts of accounts for the last part | ||
``` | ||
| ||
`run.sh` prints Markdown: the machine, then a table for each part. Its files | ||
go under `BENCH_DIR`, by default `bench/store/target/data`, and are removed | ||
after each part; what a sync costs is that directory's disk's and file | ||
system's, so `BENCH_DIR` names the disk measured. It needs cargo, Node and | ||
`ps`, and nothing of the harness's. | ||
| ||
On the runner, the `store-bench` workflow runs the same script: on a pull | ||
that changes `bench/store/`, and on `main` when the owner asks | ||
(`knotless run rerun knotless://chadtmiller.com/spec-pds --ref | ||
refs/heads/main --workflow store-bench`). Its log is the tables. | ||
| ||
Run it alone on the machine: every part times syncs or starts. | ||
| ||
## What it measures | ||
| ||
**Writes** (`store-bench write <commits> <writers>`). A commit is what a | ||
`createRecord` leaves: the commit's block, the record's, two MST nodes, and | ||
its event's frame, 4.8 KB in all, with the two nodes the account's commit | ||
before made taken out. Writers on threads of their own each write the next | ||
commit to an account drawn from 40, and wait until it is on disk: 1500 | ||
commits from 16 writers, as the PDS benchmark's `createRecord` part, and from | ||
4. Each layout is warmed with a tenth as many first. The layouts: | ||
| ||
| layout | is | | ||
|---|---| | ||
| a log for each account | the server's: each commit one frame of JSON, bytes as hex, appended to its account's log (`pds_store::Wal`), commits to one account that wait at once sharing a sync | | ||
| one log for all | the same frames in one log, so that commits to any accounts share a sync | | ||
| SQLite for each account | a database for each account in WAL mode, `synchronous=FULL`: a commit is a transaction of its blocks into a table by CID, the nodes taken out deleted, its record's path and its event into tables of their own | | ||
| one SQLite for all | the same tables in one database, on one connection | | ||
| ||
Every layout's commit is synced to the disk before it is answered. On macOS | ||
that is `F_FULLFSYNC` for all of them (`PRAGMA fullfsync=ON` for SQLite), | ||
and two more rows show SQLite as it runs there by default, its `fsync` | ||
leaving the drive's cache unflushed; elsewhere `fsync` is the sync, and | ||
those rows would repeat the two above. Per layout: commits per second, the | ||
p50 and p99 of a commit's time, and for the logs, how many syncs were made | ||
and how long each took. | ||
| ||
**A log replayed** (`store-bench scan <MiB>...`). A log of those frames of | ||
the size given is written, then read as a start or a cold account's load | ||
reads it (`pds_store::scan_file`): each frame's check computed and its JSON | ||
parsed. The best of three, so the file is in the system's cache: what the | ||
replay itself costs, a floor under what loading an account with that much | ||
log takes. | ||
| ||
**The service log by the number of accounts** (`node service.mjs | ||
[accounts...]`). For each count, without and with an email and a password | ||
on every account: the server (`target/release/pds`, with the scale run's | ||
`PDS_CACHE_BYTES`, 16 MiB) is started on an empty data directory, once | ||
unmeasured and then three times, the slowest the empty start; the | ||
accounts' entries are written | ||
into its service log as the server writes them, none with a repository; it | ||
is started on that log; one invite code is made, a write to the service log | ||
that makes its compaction due, and its resident memory sampled until the | ||
checkpoint is in place; then it is started on the checkpoint. The table has | ||
each start's time until `describeServer` answers, beside the bound | ||
`spec/STORE.md` gives a start (twice the empty start and 250 ms); the | ||
resident memory idle, and the most while compacting, beside the bound it | ||
gives memory (the empty start's, 32 MiB, the cache and 4 KiB an account). | ||
A figure over its bound is in bold. | ||
| ||
## Reading the results | ||
| ||
- A machine's numbers compare only with the same machine's: the disk and | ||
how it syncs decide the write part. `RESULTS.md` says which machine each | ||
table is from. | ||
- The accounts of the last part hold no sessions, app passwords, | ||
preferences or OAuth state, which a real account adds to the same log: | ||
its figures are a floor. | ||
- `service.mjs` writes the service log's own format, and the write part the | ||
server's commit frames: a change to either format is a change here. | ||
- SQLite is run as a careful server would run it for this, not tuned | ||
further: one connection a database, prepared statements, a transaction a | ||
commit, its page size and checkpoints as they come. | ||
bench/store/RESULTS.mdnew+148−0
| @@ -0,0 +1,148 @@ | ||
# The store benchmark: results | ||
| ||
`just store-bench` ([`README.md`](README.md)), one section a machine. A | ||
machine's numbers compare only with its own. | ||
| ||
## The runner, Linux | ||
| ||
The `store-bench` workflow's run on `runner.knotless.dev`, in the image | ||
`rust:1.98`. | ||
| ||
- Linux 6.8.0-146-generic x86_64, 12 cores, load 2.38; its files on the | ||
run's overlay over the runner's disk. Every sync is `fsync`. | ||
- cargo 1.98.1; node v24.22.1; the repository at `cb07f18`. | ||
| ||
### Writes | ||
| ||
1500 commits from 16 writers over 40 accounts, each on disk (fsync) before it is answered. | ||
| ||
| layout | per s | p50 ms | p99 ms | log syncs | ms per sync | | ||
|---|--:|--:|--:|--:|--:| | ||
| a log for each account (the server's) | 696 | 19.2 | 60.2 | 1447 | 19.64 | | ||
| one log for all | 618 | 16.4 | 156.5 | 292 | 8.19 | | ||
| SQLite for each account | 605 | 20.9 | 77.5 | | | | ||
| one SQLite for all | 107 | 10.5 | 1474.7 | | | | ||
| ||
1500 commits from 4 writers over 40 accounts, each on disk (fsync) before it is answered. | ||
| ||
| layout | per s | p50 ms | p99 ms | log syncs | ms per sync | | ||
|---|--:|--:|--:|--:|--:| | ||
| a log for each account (the server's) | 205 | 18.5 | 37.0 | 1498 | 18.86 | | ||
| one log for all | 253 | 16.2 | 27.7 | 695 | 8.46 | | ||
| SQLite for each account | 189 | 19.3 | 46.5 | | | | ||
| one SQLite for all | 111 | 8.4 | 701.3 | | | | ||
| ||
- Syncs of different files go on side by side here: sixteen writers make | ||
1447 syncs of 20 ms each in two seconds. So a log for each account is as | ||
fast as one log for all from 16 writers, and a fifth slower from 4, where | ||
one log's writers still share syncs. One log for all would buy little | ||
where the server is deployed; what it buys on the Mac is `F_FULLFSYNC`'s | ||
cost. | ||
- SQLite for each account is a tenth or so behind the logs, never ahead. | ||
One SQLite for all is the slowest layout, at a sixth of the logs' rate | ||
from 16 writers, its p99 over a second. | ||
| ||
### A log replayed | ||
| ||
| log MiB | frames | replay ms | MiB per s | | ||
|--:|--:|--:|--:| | ||
| 64 | 6599 | 66 | 966 | | ||
| 512 | 52777 | 531 | 963 | | ||
| ||
### The service log by the number of accounts | ||
| ||
| accounts | email and password | service log MiB | start on the log ms | start on the checkpoint ms | start bound ms | idle RSS MiB | compaction ms | peak RSS compacting MiB | RSS bound MiB | | ||
|--:|---|--:|--:|--:|--:|--:|--:|--:|--:| | ||
| 10000 | no | 7.1 | **413** | **383** | 314 | 32.3 | 191 | **103.6** | 103.2 | | ||
| 10000 | yes | 8.6 | **727** | **725** | 307 | 37.0 | 229 | **113.7** | 103.2 | | ||
| 30000 | no | 21.4 | **1129** | **1119** | 361 | 65.3 | 553 | **280.4** | 181.3 | | ||
| 30000 | yes | 25.8 | **4251** | **4204** | 313 | 80.5 | 615 | **312.9** | 181.3 | | ||
| 100000 | no | 71.4 | **3694** | **3602** | 310 | 172.6 | 1628 | **900.5** | 454.7 | | ||
| 100000 | yes | 85.9 | **115145** | **118117** | 310 | 219.0 | 1898 | **1008.2** | 454.8 | | ||
| ||
As on the Mac, below, which says why: over both bounds from 10000 | ||
accounts, and two minutes to start with 100000 that have emails. | ||
| ||
## Apple M1 Pro, macOS | ||
| ||
- Darwin 25.5.0 arm64, 8 cores, 32 GiB; APFS on the internal SSD | ||
(`/dev/disk3s5`). Every sync is `F_FULLFSYNC`, a flush through the | ||
drive's cache. | ||
- cargo 1.99.1; node v24.22.1; the repository at `bbbecb5`, the benchmark | ||
as it was added. | ||
- The machine was not alone: its load was 34 as the run began, from other | ||
work. The write part, run three more times that day under loads of 14 to | ||
37, gave 16 writers 423 to 465 commits per second on a log for each | ||
account, 887 to 1341 on one log for all, 216 to 227 on SQLite for each | ||
account and 178 to 197 on one SQLite for all: the order never changed, | ||
and one log for all is the row the load moves most. | ||
| ||
### Writes | ||
| ||
1500 commits from 16 writers over 40 accounts, each on disk (F_FULLFSYNC) before it is answered. | ||
| ||
| layout | per s | p50 ms | p99 ms | log syncs | ms per sync | | ||
|---|--:|--:|--:|--:|--:| | ||
| a log for each account (the server's) | 476 | 28.5 | 130.7 | 1450 | 22.45 | | ||
| one log for all | 569 | 19.9 | 169.8 | 516 | 4.87 | | ||
| SQLite for each account | 209 | 69.1 | 206.6 | | | | ||
| one SQLite for all | 192 | 64.2 | 361.5 | | | | ||
| SQLite for each account, fsync without F_FULLFSYNC | 3130 | 3.0 | 50.2 | | | | ||
| one SQLite for all, fsync without F_FULLFSYNC | 4826 | 2.2 | 12.7 | | | | ||
| ||
1500 commits from 4 writers over 40 accounts, each on disk (F_FULLFSYNC) before it is answered. | ||
| ||
| layout | per s | p50 ms | p99 ms | log syncs | ms per sync | | ||
|---|--:|--:|--:|--:|--:| | ||
| a log for each account (the server's) | 229 | 16.6 | 35.9 | 1499 | 14.37 | | ||
| one log for all | 409 | 9.1 | 22.8 | 714 | 5.08 | | ||
| SQLite for each account | 222 | 18.0 | 35.1 | | | | ||
| one SQLite for all | 188 | 18.0 | 86.0 | | | | ||
| SQLite for each account, fsync without F_FULLFSYNC | 4592 | 0.7 | 5.5 | | | | ||
| one SQLite for all, fsync without F_FULLFSYNC | 5906 | 0.5 | 4.5 | | | | ||
| ||
- At the same durability SQLite is no faster than the server's logs: level | ||
with them from 4 writers, half their rate from 16. Its rows without | ||
`F_FULLFSYNC` are what it does on macOS by default, and what the PDS | ||
benchmark's SQLite servers' write numbers are paid with | ||
(`../RESULTS.md`, "Durability differs"). | ||
- A log for each account is a sync for each account's commits: 1450 syncs | ||
for 1500 commits, each 22 ms as sixteen wait on the one drive, where one | ||
log for all made 516 of 5 ms. `F_FULLFSYNC` flushes the whole drive, so | ||
syncs of different files queue behind each other here; whether they do | ||
on Linux is what the runner's section says. | ||
| ||
### A log replayed | ||
| ||
| log MiB | frames | replay ms | MiB per s | | ||
|--:|--:|--:|--:| | ||
| 64 | 6599 | 60 | 1064 | | ||
| 512 | 52777 | 480 | 1066 | | ||
| ||
A log may grow to its checkpoint's size before it is compacted, so an | ||
account whose table is half a gibibyte may take half a second of replay | ||
alone on its first request after a start, of the second `spec/STORE.md` | ||
gives it. | ||
| ||
### The service log by the number of accounts | ||
| ||
| accounts | email and password | service log MiB | start on the log ms | start on the checkpoint ms | start bound ms | idle RSS MiB | compaction ms | peak RSS compacting MiB | RSS bound MiB | | ||
|--:|---|--:|--:|--:|--:|--:|--:|--:|--:| | ||
| 10000 | no | 7.1 | **293** | 289 | 292 | 35.0 | 94 | **108.3** | 105.2 | | ||
| 10000 | yes | 8.6 | **462** | **458** | 298 | 39.8 | 110 | **119.5** | 105.2 | | ||
| 30000 | no | 21.4 | **839** | **903** | 291 | 69.2 | 307 | **286.6** | 183.4 | | ||
| 30000 | yes | 25.8 | **3435** | **3457** | 298 | 84.3 | 361 | **309.3** | 183.4 | | ||
| 100000 | no | 71.4 | **4380** | **5120** | 303 | 128.1 | 1830 | **812.5** | 456.8 | | ||
| 100000 | yes | 85.9 | **74972** | **43015** | 316 | 162.0 | 996 | **949.8** | 456.8 | | ||
| ||
- The start grows with the accounts, about 27 µs each on a quiet machine | ||
(2680 ms for 100000): a sample of that start has four fifths of its time | ||
deriving each account's public key from its signing key as its entry is | ||
read. | ||
- With emails it grows with their square: each account's email is compared | ||
with every one before it. | ||
- Compacting the service log holds all of it in memory as parsed JSON, | ||
about 7 KiB an account for these accounts, over the memory bound from | ||
10000 accounts. | ||
- The scale run (`spec/STORE.md`, "How it is checked") makes 2000 accounts | ||
without passwords, and sees none of this. | ||
bench/store/run.shnew+37−0
| @@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
# The store benchmark, whole (README.md): Markdown on stdout, to read or to | ||
# put in RESULTS.md. The server is ../../target/release/pds, built already | ||
# (`just build`); CARGO names the cargo that builds the rest (`cargo` by | ||
# default); arguments are service.mjs's, its counts of accounts. | ||
set -eu | ||
cd "$(dirname "$0")" | ||
cargo=${CARGO:-cargo} | ||
dir=${BENCH_DIR:-$PWD/target/data} | ||
mkdir -p "$dir" | ||
$cargo build --release >&2 | ||
bench=target/release/store-bench | ||
| ||
echo "## Machine" | ||
echo | ||
echo "- $(uname -srm), $(getconf _NPROCESSORS_ONLN) cores, load $(uptime | sed 's/.*load averages\{0,1\}: *//')" | ||
if command -v findmnt >/dev/null 2>&1; then | ||
echo "- its files on: $(findmnt -no SOURCE,FSTYPE,OPTIONS -T "$dir")" | ||
else | ||
echo "- its files on: $(df -P "$dir" | awk 'NR==2 {print $1}')" | ||
fi | ||
echo "- $($cargo --version); node $(node --version)" | ||
echo "- the repository at $(git rev-parse --short HEAD 2>/dev/null || echo 'a commit git cannot name here')" | ||
echo | ||
echo "## Writes" | ||
echo | ||
$bench write 1500 16 | ||
echo | ||
$bench write 1500 4 | ||
echo | ||
echo "## A log replayed" | ||
echo | ||
$bench scan 64 512 | ||
echo | ||
echo "## The service log by the number of accounts" | ||
echo | ||
node service.mjs "$@" | ||
bench/store/service.mjsnew+220−0
| @@ -0,0 +1,220 @@ | ||
// The store benchmark's third part (README.md): how the server's start, its | ||
// memory, and the compaction of its service log follow the number of | ||
// accounts. Prints a Markdown table. | ||
// | ||
// node service.mjs [accounts...] by default 10000 30000 100000 | ||
// | ||
// Each count runs twice, its accounts without and with an email and a | ||
// password. The accounts are not made through the server, which would take | ||
// a PLC operation and a password hash each: their entries are written into | ||
// the service log, `accounts.0.log`, as the server writes them (frames of | ||
// `account` entries, `pds-server`'s `log`), none with a repository yet, so | ||
// this knows the log's format and breaks when it changes. The server is | ||
// `../../target/release/pds` (`just build`), or `PDS_BIN`; its data | ||
// directories are under `BENCH_DIR`, by default `target/data` here, and are | ||
// removed after. | ||
| ||
import { execFileSync, spawn } from 'node:child_process' | ||
import { createHash } from 'node:crypto' | ||
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeSync } from 'node:fs' | ||
import { createServer } from 'node:net' | ||
import { join, resolve } from 'node:path' | ||
| ||
const here = new URL('.', import.meta.url).pathname | ||
const BIN = resolve(process.env.PDS_BIN ?? join(here, '../../target/release/pds')) | ||
const ROOT = resolve(process.env.BENCH_DIR ?? join(here, 'target/data')) | ||
const COUNTS = process.argv.slice(2).map(Number) | ||
if (COUNTS.some((n) => !(n >= 1))) { | ||
console.error('node service.mjs [accounts...]') | ||
process.exit(2) | ||
} | ||
if (!COUNTS.length) COUNTS.push(10000, 30000, 100000) | ||
if (!existsSync(BIN)) { | ||
console.error(`no server at ${BIN}: \`just build\` first, or set PDS_BIN`) | ||
process.exit(1) | ||
} | ||
| ||
/// The cache the scale run gives the server (spec/STORE.md, "How it is | ||
/// checked"), and the memory rule's other parts. | ||
const CACHE_BYTES = 16 * 1048576 | ||
const REQUEST_SLACK = 32 * 1048576 | ||
const PER_ACCOUNT = 4096 | ||
const START_SLACK = 250 | ||
const ADMIN = 'admin-pass' | ||
| ||
const sha256 = (...parts) => parts.reduce((h, p) => h.update(p), createHash('sha256')).digest() | ||
const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms)) | ||
const MiB = (bytes) => (bytes / 1048576).toFixed(1) | ||
| ||
/// A frame of a log (`pds-store`): its payload's length, the first 8 bytes | ||
/// of SHA-256 over the length and the payload, and the payload, a JSON | ||
/// array of entries. | ||
function frame(entries) { | ||
const payload = Buffer.from(JSON.stringify(entries)) | ||
const head = Buffer.alloc(4) | ||
head.writeUInt32LE(payload.length) | ||
return Buffer.concat([head, sha256(head, payload).subarray(0, 8), payload]) | ||
} | ||
| ||
/// The kinds of the entries in a log's frames. | ||
function kinds(data) { | ||
const out = new Set() | ||
for (let pos = 0; data.length - pos >= 12; ) { | ||
const n = data.readUInt32LE(pos) | ||
for (const e of JSON.parse(data.subarray(pos + 12, pos + 12 + n))) out.add(e.t) | ||
pos += 12 + n | ||
} | ||
return out | ||
} | ||
| ||
const B32 = 'abcdefghijklmnopqrstuvwxyz234567' | ||
function base32(bytes, chars) { | ||
let out = '' | ||
for (let i = 0, bits = 0, acc = 0; out.length < chars; ) { | ||
if (bits < 5) { | ||
acc = (acc << 8) | bytes[i++] | ||
bits += 8 | ||
} | ||
out += B32[(acc >> (bits - 5)) & 31] | ||
bits -= 5 | ||
} | ||
return out | ||
} | ||
| ||
/// Account `i`'s entry, as `createAccount` writes it. | ||
function account(i, emails, url) { | ||
const h = sha256(String(i)) | ||
const did = `did:plc:${base32(h, 24)}` | ||
const handle = `user${i}.test` | ||
return { | ||
t: 'account', did, handle, | ||
email: emails ? `user${i}@example.com` : null, | ||
password: emails ? `scrypt$${sha256('salt', h).toString('hex')}$${sha256('hash', h).toString('hex')}` : null, | ||
key: sha256('key', h).toString('hex'), | ||
kemKey: null, | ||
didDoc: { | ||
'@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/multikey/v1', 'https://w3id.org/security/suites/secp256k1-2019/v1'], | ||
id: did, | ||
alsoKnownAs: [`at://${handle}`], | ||
verificationMethod: [{ id: `${did}#atproto`, type: 'Multikey', controller: did, publicKeyMultibase: `zQ3sh${base32(sha256('pub', h), 43)}` }], | ||
service: [{ id: '#atproto_pds', type: 'AtprotoPersonalDataServer', serviceEndpoint: url }], | ||
}, | ||
} | ||
} | ||
| ||
const freePort = () => new Promise((ok) => { | ||
const s = createServer().listen(0, '127.0.0.1', () => { | ||
const { port } = s.address() | ||
s.close(() => ok(port)) | ||
}) | ||
}) | ||
| ||
/// The server's resident memory, in bytes, as `ps` reports it. | ||
const rss = (pid) => Number(execFileSync('ps', ['-o', 'rss=', '-p', String(pid)]).toString().trim()) * 1024 | ||
| ||
/// One count of accounts, with emails and passwords or without: a row. | ||
async function measure(n, emails) { | ||
const dir = join(ROOT, `service-${n}-${emails ? 'emails' : 'plain'}`) | ||
rmSync(dir, { recursive: true, force: true }) | ||
mkdirSync(dir, { recursive: true }) | ||
const port = await freePort() | ||
const url = `http://127.0.0.1:${port}` | ||
const env = { | ||
PATH: process.env.PATH, PDS_PORT: String(port), PDS_DATA_DIR: dir, PDS_HOSTNAME: 'localhost', PDS_PUBLIC_URL: url, | ||
PDS_HANDLE_DOMAINS: '.test', PDS_PLC_URL: 'http://127.0.0.1:9', PDS_PLC_ROTATION_KEY_HEX: sha256('rotation').toString('hex'), | ||
PDS_ADMIN_PASSWORD: ADMIN, PDS_INVITE_REQUIRED: 'false', PDS_RATE_LIMITS_ENABLED: 'false', PDS_CACHE_BYTES: String(CACHE_BYTES), | ||
} | ||
const out = openSync(`${dir}.out`, 'w') | ||
| ||
/// Start the server: answers it, and how long until it answered describeServer. | ||
const start = async () => { | ||
const at = performance.now() | ||
const proc = spawn(BIN, ['serve'], { env, stdio: ['ignore', out, out] }) | ||
let exited = null | ||
proc.on('exit', (code) => (exited = code ?? 'killed')) | ||
for (;;) { | ||
if (exited !== null) throw new Error(`the server exited ${exited}: ${readFileSync(`${dir}.out`, 'utf8').slice(-2000)}`) | ||
try { | ||
const res = await fetch(`${url}/xrpc/com.atproto.server.describeServer`) | ||
await res.arrayBuffer() | ||
if (res.ok) return { proc, ms: performance.now() - at } | ||
} catch {} | ||
await sleep(2) | ||
} | ||
} | ||
const stop = (proc) => new Promise((ok) => { | ||
proc.on('exit', ok) | ||
proc.kill('SIGTERM') | ||
}) | ||
| ||
// An empty data directory: once unmeasured, as a binary's first run may | ||
// be slow, then three times, the slowest start and its memory what the | ||
// others are held against, as the scale run holds them. | ||
await stop((await start()).proc) | ||
let t0 = 0 | ||
let r0 = 0 | ||
for (let i = 0; i < 3; i++) { | ||
const { proc, ms } = await start() | ||
t0 = Math.max(t0, ms) | ||
await sleep(300) | ||
r0 = rss(proc.pid) | ||
await stop(proc) | ||
} | ||
| ||
// The accounts, into the service log; and seqs reserved, as a data | ||
// directory that ever numbered an event has them, so that no start reads | ||
// every account's own log for the last. | ||
const log = join(dir, 'accounts.0.log') | ||
const fd = openSync(log, 'a') | ||
if (!kinds(readFileSync(log)).has('seqs')) writeSync(fd, frame([{ t: 'seqs', upto: 1024 }])) | ||
for (let i = 0; i < n; i += 32) { | ||
writeSync(fd, frame(Array.from({ length: Math.min(32, n - i) }, (_, j) => account(i + j, emails, url)))) | ||
} | ||
closeSync(fd) | ||
const logBytes = statSync(log).size | ||
| ||
// Started on the log. | ||
const first = await start() | ||
await sleep(300) | ||
const idle = rss(first.proc.pid) | ||
| ||
// One write to the service log makes its compaction due: its memory is | ||
// sampled until the checkpoint is in place and the log it covers gone. | ||
const checkpoint = join(dir, 'accounts.checkpoint') | ||
const res = await fetch(`${url}/xrpc/com.atproto.server.createInviteCode`, { | ||
method: 'POST', body: '{"useCount":1}', | ||
headers: { 'content-type': 'application/json', authorization: `Basic ${Buffer.from(`admin:${ADMIN}`).toString('base64')}` }, | ||
}) | ||
if (!res.ok) throw new Error(`createInviteCode: ${res.status} ${await res.text()}`) | ||
const at = performance.now() | ||
let peak = idle | ||
let folded = null | ||
while (performance.now() - at < 300_000) { | ||
peak = Math.max(peak, rss(first.proc.pid)) | ||
if (existsSync(checkpoint) && !existsSync(log) && !existsSync(`${checkpoint}.tmp`)) { | ||
folded = performance.now() - at | ||
break | ||
} | ||
await sleep(5) | ||
} | ||
await stop(first.proc) | ||
| ||
// Started on the checkpoint. | ||
const second = await start() | ||
await stop(second.proc) | ||
closeSync(out) | ||
rmSync(dir, { recursive: true, force: true }) | ||
rmSync(`${dir}.out`, { force: true }) | ||
| ||
const ms = (x) => (x === null ? 'never' : x.toFixed(0)) | ||
const startBound = 2 * t0 + START_SLACK | ||
const rssBound = r0 + REQUEST_SLACK + CACHE_BYTES + PER_ACCOUNT * n | ||
const over = (x, bound, text) => (x > bound ? `**${text}**` : text) | ||
console.log(`| ${n} | ${emails ? 'yes' : 'no'} | ${MiB(logBytes)} | ${over(first.ms, startBound, ms(first.ms))} | ${over(second.ms, startBound, ms(second.ms))} | ${ms(startBound)} | ${MiB(idle)} | ${ms(folded)} | ${over(peak, rssBound, MiB(peak))} | ${MiB(rssBound)} |`) | ||
} | ||
| ||
console.log('| accounts | email and password | service log MiB | start on the log ms | start on the checkpoint ms | start bound ms | idle RSS MiB | compaction ms | peak RSS compacting MiB | RSS bound MiB |') | ||
console.log('|--:|---|--:|--:|--:|--:|--:|--:|--:|--:|') | ||
for (const n of COUNTS) { | ||
for (const emails of [false, true]) await measure(n, emails) | ||
} | ||
.gitignore+1−0
| @@ -5,3 +5,4 @@ | ||
/bench/vendor | ||
/web/node_modules | ||
/web/dist | ||
/bench/store/target | ||
Justfile+4−0
| @@ -50,6 +50,10 @@ test: web | ||
bench: | ||
cd harness && node bench.mjs --setup && node bench.mjs --rounds 3 --json ../bench/results.json | ||
| ||
# The store benchmark (bench/store/README.md): the server's logs beside SQLite under the same commits, a log replayed, and the server's start and memory by the number of accounts in its service log; Markdown on stdout. Arguments are counts of accounts, as `just store-bench 10000 200000`. | ||
store-bench *args: build | ||
CARGO="{{cargo}}" bench/store/run.sh {{args}} | ||
| ||
# The compatibility check (compat/README.md): build every implementation at its pin (bench/impls.json), then every core area of each beside the reference; the tables on stdout, the raw results in compat/results.json. Arguments pass through, as `just compat --impls zds --areas oauth`. | ||
compat *args: | ||
cd harness && node bench.mjs --setup && node compat.mjs --steps 200 --json ../compat/results.json {{args}} | ||
README.md+13−0
| @@ -232,6 +232,19 @@ time and memory. Each implementation is an adapter in it, pinned in | ||
cd harness && node bench.mjs --setup && node bench.mjs --rounds 3 --json ../bench/results.json | ||
``` | ||
| ||
`bench/store/` benchmarks how the server keeps its data, apart from the | ||
rest of it: its logs (`crates/pds-store`) beside SQLite under the same | ||
commits, each synced before it is answered; a log replayed; and the | ||
server's start and memory by the number of accounts in its service log, | ||
beside `spec/STORE.md`'s bounds. `bench/store/README.md` says what each | ||
part measures, and `bench/store/RESULTS.md` holds the last results, by | ||
machine. The `store-bench` workflow runs it on the runner, on a pull that | ||
changes it and when the owner asks. | ||
| ||
```sh | ||
just store-bench | ||
``` | ||
| ||
`harness/compat.mjs` checks how closely any PDS behaves like the reference, | ||
area by area: the core of `compare.mjs`'s checks (OAuth and its scopes, | ||
sessions, accounts, records, validation, the repository, sync, the | ||