chadtmiller.com/monolith
An atproto PDS
0
0
harness: a start over its bound is taken again before it fails
docs/guide/comparing.md+1−1
| @@ -154,7 +154,7 @@ it reorganizes its data, compares every read and the firehose's | ||
`OutdatedCursor` replays with the reference, and then holds the data | ||
directory to three times the live state and a constant for each account, | ||
and each start to twice the median of the empty starts timed around it, | ||
and 250 ms. | ||
and 250 ms, taking a start over it again up to twice before it fails. | ||
| ||
`--scale` holds the server alone to STORE.md's | ||
[scale rules](../../spec/STORE.md#scale), with a 16 MiB cache: its resident | ||
harness/checks/store.mjs+42−23
| @@ -52,6 +52,8 @@ const START_SLACK = 250 | ||
/// How many starts on an empty data directory are timed on each side of a | ||
/// start of the server. | ||
const EMPTY_STARTS = 2 | ||
/// How many times more a start over its bound is taken, on the same data. | ||
const RETAKES = 2 | ||
/// How many writes a crash makes, waiting to see the server reorganize its | ||
/// data, before it kills the server all the same. | ||
const LEAD_WRITES = 200 | ||
| @@ -427,38 +429,55 @@ const median = (xs) => { | ||
} | ||
| ||
/// Each start of the server timed against its bound: its time, and the | ||
/// median of the empty starts timed around it. | ||
/// median of the empty starts timed around it; of a start taken again, the | ||
/// take nearest within its bound. | ||
const starts = [] | ||
| ||
/// One take of a start, the server down: EMPTY_STARTS starts on empty data | ||
/// directories, then the server's own, timed; the server killed again as | ||
/// soon as it answers, EMPTY_STARTS more, and the server started once more | ||
/// on its data. Answers the start's time, the empty starts', and its bound: | ||
/// twice their median, plus START_SLACK. | ||
async function take() { | ||
const empty = [] | ||
for (let i = 0; i < EMPTY_STARTS; i++) empty.push(await emptyStart()) | ||
server.start() | ||
const ms = await waitReady(server, cand.url) | ||
await server.kill() | ||
for (let i = 0; i < EMPTY_STARTS; i++) empty.push(await emptyStart()) | ||
server.start() | ||
await waitReady(server, cand.url) | ||
return { ms, empty, bound: 2 * median(empty) + START_SLACK } | ||
} | ||
| ||
/// Kill the server and start it again, led to its reorganizing its data if | ||
/// `lead` is given, its start timed among EMPTY_STARTS starts on empty data | ||
/// directories while it is down before it, and EMPTY_STARTS after it, the | ||
/// server killed again as soon as it answers and then started once more on | ||
/// its data, so that the machine's load slows them alike. The start must be | ||
/// within twice the median of those, plus START_SLACK (spec/STORE.md, | ||
/// "Bounds", "Starting"); the space repos, takedowns and preferences must | ||
/// have survived. | ||
/// `lead` is given, its start timed among starts on empty data directories | ||
/// so that the machine's load slows them alike (take). A start over its | ||
/// bound is taken again, the server killed and started on the same data, | ||
/// up to RETAKES times more, and fails only if every take is over its own | ||
/// bound (spec/STORE.md, "Bounds", "Starting"); the space repos, takedowns | ||
/// and preferences must have survived. | ||
async function restart(lead) { | ||
const empty = [] | ||
const ms = await crash({ | ||
const takes = [] | ||
await crash({ | ||
lead, | ||
accountsMade: false, | ||
async start() { | ||
for (let i = 0; i < EMPTY_STARTS; i++) empty.push(await emptyStart()) | ||
server.start() | ||
const took = await waitReady(server, cand.url) | ||
await server.kill() | ||
for (let i = 0; i < EMPTY_STARTS; i++) empty.push(await emptyStart()) | ||
server.start() | ||
await waitReady(server, cand.url) | ||
return took | ||
takes.push(await take()) | ||
while (takes.at(-1).ms > takes.at(-1).bound && takes.length <= RETAKES) { | ||
await server.kill() | ||
takes.push(await take()) | ||
} | ||
return takes[0].ms | ||
}, | ||
}) | ||
const base = median(empty) | ||
starts.push({ ms, empty: base }) | ||
console.error(`start ${crashes.count}: ${ms} ms, on empty data directories ${empty.join(', ')} ms${crashes.reorganizing ? `, ${crashes.reorganizing} of them while reorganizing` : ''}`) | ||
if (ms > 2 * base + START_SLACK) { | ||
await differ('starting again', { after: `${run.step} steps`, crashes: crashes.count }, `describeServer within ${2 * base + START_SLACK} ms: twice the median of the starts on an empty data directory timed around it, ${empty.join(', ')} ms, and ${START_SLACK} ms (spec/STORE.md, "Bounds")`, `${ms} ms`) | ||
const best = takes.reduce((a, t) => (t.ms - t.bound < a.ms - a.bound ? t : a)) | ||
starts.push({ ms: best.ms, empty: median(best.empty) }) | ||
const timed = takes.map((t) => `${t.ms} ms, on empty data directories ${t.empty.join(', ')} ms`).join('; taken again, ') | ||
console.error(`start ${crashes.count}: ${timed}${crashes.reorganizing ? `; ${crashes.reorganizing} of them while reorganizing` : ''}`) | ||
if (best.ms > best.bound) { | ||
const want = takes.map((t) => `describeServer within ${t.bound} ms: twice the median of the starts on an empty data directory timed around it, ${t.empty.join(', ')} ms, and ${START_SLACK} ms`) | ||
await differ('starting again', { after: `${run.step} steps`, crashes: crashes.count, takes: takes.length }, `in one take of ${takes.length}, on the same data, ${want.join('; or ')} (spec/STORE.md, "Bounds")`, takes.map((t) => `${t.ms} ms`).join(', ')) | ||
} | ||
await survive('a restart') | ||
} | ||
spec/STORE.md+8−1
| @@ -148,7 +148,10 @@ bucket holds what `BLOBS.md` says. | ||
accounts, with what they hold, or with how many writes they have had: | ||
started on any data directory, the server answers `describeServer` | ||
within twice the time it takes to start on an empty one, on the same | ||
machine and under the same load, plus 250 ms. | ||
machine and under the same load, plus 250 ms. A start that a passing | ||
load slowed more than the starts beside it breaks no bound when the | ||
server, started again on the same data, meets it: what does not hold | ||
is a start that is slow each time. | ||
An account's state may be read from disk on its first use after that | ||
(below). | ||
| ||
| @@ -279,6 +282,10 @@ its own, so that the machine's load at that moment slows them alike: two | ||
while the server is down before its start, and two after, the server | ||
killed again as soon as it answers and then started once more on its data; | ||
the start must take at most twice the median of those four, plus 250 ms. | ||
A start over that bound is taken again, up to twice more: the server | ||
killed and started on the same data among four new starts on empty data | ||
directories, as before. The start fails only if every take is over its own | ||
bound, as a start whose time grows with the data is each time. | ||
| ||
At the end it rewrites every key of every account eight times, at once, | ||
then waits `2 W` and a second, kills the server and starts it again, and, | ||