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

harness: each start held to empty starts timed around it

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:harness/start-bound-baseline
docs/guide/comparing.md+2−1
@@ -153,7 +153,8 @@ records, blobs and space records many times over, kills the server while
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 first.
and each start to twice the median of the empty starts timed around it,
and 250 ms.
`--scale` holds the server alone to STORE.md's
[scale rules](../../spec/STORE.md#scale), with a 16 MiB cache: its resident
harness/checks/backup.mjs+1−1
@@ -25,7 +25,7 @@ const PUTS = 8
/// spec/OPERATIONS.md, "Kept"), and its guard keeps it from the harness's
/// services (spec/PROXY.md); with no crawlers too, nothing it does reaches
/// what the run checks.
const APART = ['PDS_METRICS_PORT', 'OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_EXPORTER_OTLP_HEADERS', 'PDS_DEV_MAIL_DIR', 'PDS_EMAIL_SMTP_URL', 'PDS_EMAIL_FROM', 'PDS_DISABLE_SSRF_PROTECTION', 'PDS_LOG_DIR']
export const APART = ['PDS_METRICS_PORT', 'OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_EXPORTER_OTLP_HEADERS', 'PDS_DEV_MAIL_DIR', 'PDS_EMAIL_SMTP_URL', 'PDS_EMAIL_FROM', 'PDS_DISABLE_SSRF_PROTECTION', 'PDS_LOG_DIR']
const broke = (what, request, want, got) => differ(`a server started on a snapshot: ${what}`, request, want, got, 'spec/DURABILITY.md, "Backups"')
harness/checks/crashes.mjs+11−4
@@ -33,8 +33,10 @@ export const crashes = { count: 0, inFlight: 0, landed: 0, restartMs: [], reorga
/// accounts carries on after it, unless `accountsMade` is false. `lead`, if
/// given, runs first, and answers whether the server is to be killed at
/// once, as when it is seen reorganizing its data (spec/STORE.md), with
/// nothing on its way. Answers how long the server took to start again.
export async function crash({ lead, accountsMade = true } = {}) {
/// nothing on its way. `start`, if given, starts the server again in place
/// of starting it and waiting for it to answer, and answers how long its
/// start took. Answers how long the server took to start again.
export async function crash({ lead, accountsMade = true, start = startAgain } = {}) {
await oauthBeforeCrash()
await oauthClientsBeforeCrash()
await mcpBeforeCrash()
@@ -51,8 +53,7 @@ export async function crash({ lead, accountsMade = true } = {}) {
await server.kill()
crashes.count += 1
if (now) crashes.reorganizing += 1
server.start()
const ms = await waitReady(server, cand.url)
const ms = await start()
crashes.restartMs.push(ms)
if (FIREHOSE) resubscribe()
if (op) {
@@ -82,6 +83,12 @@ export async function crash({ lead, accountsMade = true } = {}) {
return ms
}
/// The server started again, and how long it took to answer.
function startAgain() {
server.start()
return waitReady(server, cand.url)
}
/// A put to the account's repository on its way.
function inFlightPut(acct) {
const collection = pick(COLLECTIONS)
harness/checks/operations.mjs+4−2
@@ -630,10 +630,12 @@ const sentSince = (life) => sent.filter((r) => r.life === life.n && r.status > 0
/// Whether spans of a request that ended at `t` may be lost: in the
/// outage, until an export could have gone after it, or just before the
/// server was killed.
/// server was killed, from when it was sent SIGKILL, which a process in the
/// middle of a disk write may outlive by seconds on a loaded machine, to
/// when it exited.
function mayBeLost(t) {
if (outageAt.hang !== null && t >= outageAt.hang - 1500 && t <= (outageAt.up ?? Infinity) + Number(OTEL_ENV.OTEL_BSP_EXPORT_TIMEOUT) + 1500) return true
return server.lives.some((l) => l.how === 'SIGKILL' && l.ended !== null && t >= l.ended - 1500 && t <= l.ended)
return server.lives.some((l) => l.how === 'SIGKILL' && l.ended !== null && t >= (l.signalled ?? l.ended) - 1500 && t <= l.ended)
}
/// Every span held to its request: one SERVER span for each request
harness/checks/store.mjs+84−19
@@ -6,18 +6,21 @@
// time. How the server lays its data out is its own: only the directory's
// size, and its files being made, removed or shortened, are seen.
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
import { spawn } from 'node:child_process'
import { chmodSync, existsSync, mkdtempSync, openSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { isDeepStrictEqual } from 'node:util'
import { BACKFILL_MS, CHECK_EVERY, CRASH_EVERY, FIREHOSE, ONLY, STEPS } from '../lib/args.mjs'
import { BACKFILL_MS, CHECK_EVERY, CRASH_EVERY, FIREHOSE, ONLY, STEPS, command } from '../lib/args.mjs'
import { below, chance, pick, rand } from '../lib/random.mjs'
import { cand, dataDir, ref, server, wait, waitReady } from '../lib/processes.mjs'
import { cand, dataDir, freePort, ref, server, wait, waitReady } from '../lib/processes.mjs'
import { ADMIN_PASSWORD } from '../lib/env.mjs'
import { fail } from '../lib/plc.mjs'
import { count, differ, run } from '../lib/report.mjs'
import { accounts, didOf, exists, nextBatch, noteCommit, noteWrite } from '../lib/state.mjs'
import { both, normalize, shown, xrpcHttp } from '../lib/xrpc.mjs'
import { createAccount, createFirstAccounts, createSession } from './accounts.mjs'
import { APART } from './backup.mjs'
import { blobRecord, getBlob, listBlobs, uploadBlob } from './blobs.mjs'
import { crash, crashes } from './crashes.mjs'
import { getBlocks, getGoneBlocks, syncGetRecord } from './federation.mjs'
@@ -46,6 +49,9 @@ const PER_ACCOUNT = 131072
const SERVER_SLACK = 1048576
const SETTLE_MS = 10_000
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 writes a crash makes, waiting to see the server reorganize its
/// data, before it kills the server all the same.
const LEAD_WRITES = 200
@@ -382,18 +388,79 @@ async function live(acct) {
return { bytes: repo.bytes.length + blobs + space.bytes, repo: repo.bytes.length, blobs, space: space.bytes }
}
/// Where the servers started on empty data directories write their output,
/// apart from those directories, which must be empty: made at the first.
let emptyLogs = null
/// The server's command and environment started on an empty data directory
/// of its own, on a port of its own, apart from the run as a snapshot's copy
/// is (backup.mjs), and timed as the server's starts are; then killed, and
/// its directory removed. Answers how long it took to answer describeServer.
async function emptyStart() {
if (!emptyLogs) {
const logDir = mkdtempSync(join(tmpdir(), 'pds-empty-log-'))
emptyLogs = { logPath: join(logDir, 'server.log'), errPath: join(logDir, 'server.err') }
emptyLogs.out = openSync(emptyLogs.logPath, 'a')
emptyLogs.err = openSync(emptyLogs.errPath, 'a')
}
const dir = mkdtempSync(join(tmpdir(), 'pds-empty-'))
// Open to all, as the run's own was at its first start.
chmodSync(dir, 0o755)
const port = await freePort()
const url = `http://127.0.0.1:${port}`
const env = { ...process.env, ...server.env, PDS_PORT: String(port), PDS_PUBLIC_URL: url, PDS_DATA_DIR: dir, PDS_CRAWLERS: '' }
for (const k of APART) delete env[k]
const p = { name: 'server on an empty data directory', logPath: emptyLogs.logPath, errPath: emptyLogs.errPath, exited: null }
const proc = spawn(command[0], command.slice(1), { env, stdio: ['ignore', emptyLogs.out, emptyLogs.err] })
const gone = new Promise((ok) => proc.on('exit', (code, signal) => ok((p.exited = { code, signal }))))
const ms = await waitReady(p, url)
proc.kill('SIGKILL')
await gone
rmSync(dir, { recursive: true, force: true })
return ms
}
const median = (xs) => {
const s = [...xs].sort((x, y) => x - y)
const m = s.length >> 1
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2
}
/// Each start of the server timed against its bound: its time, and the
/// median of the empty starts timed around it.
const starts = []
/// Kill the server and start it again, led to its reorganizing its data if
/// `lead` is given; the start must be within the starting bound of `base`,
/// the first starts' time, if given (spec/STORE.md, "Bounds"); the space
/// repos, takedowns and preferences must have survived.
async function restart(base, lead) {
const ms = await crash({ lead, accountsMade: false })
console.error(`start ${crashes.count}: ${ms} ms${crashes.reorganizing ? `, ${crashes.reorganizing} of them while reorganizing` : ''}`)
if (base !== undefined && 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 first start, ${base} ms, and ${START_SLACK} ms`, `${ms} ms`)
/// `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.
async function restart(lead) {
const empty = []
const ms = 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
},
})
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`)
}
await survive('a restart')
return ms
}
const STEPS_BY_WEIGHT = [
@@ -417,10 +484,8 @@ export async function storeRun() {
for (const acct of accounts) for (const key of [...KEYS, TD]) await rewrite(acct, key)
for (const acct of accounts) for (let i = 0; i < 4; i++) await spaceWrite(acct)
await checkRepos()
// The first start timed, once the accounts hold what they will.
let base = 0
for (let i = 0; i < 3; i++) base = Math.max(base, await restart())
console.error(`first starts: at most ${base} ms`)
// Started again, once the accounts hold what they will.
for (let i = 0; i < 3; i++) await restart()
const total = STEPS_BY_WEIGHT.reduce((n, [, w]) => n + w, 0)
for (run.step = 1; run.step <= STEPS; run.step++) {
@@ -431,7 +496,7 @@ export async function storeRun() {
break
}
}
if (CRASH_EVERY && run.step % CRASH_EVERY === 0) await restart(base, toReorganizing)
if (CRASH_EVERY && run.step % CRASH_EVERY === 0) await restart(toReorganizing)
else if (run.step % CHECK_EVERY === 0) await checkRepos()
if (run.step % 100 === 0) console.error(`${run.step} steps agree`)
}
@@ -456,10 +521,10 @@ export async function storeRun() {
await coldReads()
// Out of the window now: all but the latest writes' events.
await windowReplay()
const last = await restart(base)
await restart()
await checkRepos()
await windowReplay()
return { report, base, last, cold }
return { report, starts, cold }
}
/// spec/STORE.md, "Bounds", "Settled": a write to each account, after 2 W
harness/lib/adapters/common.mjs+6−4
@@ -22,10 +22,10 @@ export const basic = (user, password) => `Basic ${Buffer.from(`${user}:${passwor
/// standard output to `logPath` and its standard error to `errPath`.
/// `p.env` is its environment, which a start may change; `p.ulimit`, if
/// set, the file descriptors it is started with at most. `p.lives` is each
/// start, `{started, env, outFrom, errFrom, ended, how, exited, outTo,
/// errTo}`: when, with what environment, where in each file its output
/// starts and ends, and how it ended (`SIGKILL`, `SIGTERM`, or `exit` of
/// its own accord).
/// start, `{started, env, outFrom, errFrom, ended, how, signalled, exited,
/// outTo, errTo}`: when, with what environment, where in each file its
/// output starts and ends, how it ended (`SIGKILL`, `SIGTERM`, or `exit` of
/// its own accord), and when it was sent the signal it ended by.
export function child(name, cmd, env, logPath, errPath) {
const out = openSync(logPath, 'a')
const err = openSync(errPath, 'a')
@@ -50,6 +50,7 @@ export function child(name, cmd, env, logPath, errPath) {
if (!dying || p.exited) return p.exited
const life = p.lives.at(-1)
life.how ??= signal
life.signalled ??= now()
const gone = new Promise((ok) => dying.once('exit', (code, sig) => ok({ code, signal: sig })))
dying.kill(signal)
return Promise.race([gone, ...(ms === Infinity ? [] : [new Promise((ok) => setTimeout(() => ok(null), ms))])])
@@ -96,6 +97,7 @@ export function container(name, env, logPath, errPath, teardown) {
p.stop = async (signal = 'SIGKILL', ms = Infinity) => {
if (!ended || p.exited) return p.exited
p.lives.at(-1).how ??= signal
p.lives.at(-1).signalled ??= now()
await sh('docker', ['kill', '--signal', signal, name])
return Promise.race([ended, ...(ms === Infinity ? [] : [new Promise((ok) => setTimeout(() => ok(null), ms))])])
}
harness/compare.mjs+4−3
@@ -154,12 +154,13 @@ if (MOVES) {
await shutdown(0)
}
if (STORE) {
const { report, base, last, cold } = await storeRun()
const { report, starts, cold } = await storeRun()
await checkOperations()
console.error(`\nall ${STEPS} store steps agree (seed ${SEED}), ${accounts.length} accounts, ${recordCount()} records${cold ? `, a cold first use read ${cold.read} bytes of at most ${cold.most}` : ', a cold first use\'s reads not counted here'}`)
for (const line of report) console.error(` ${line}`)
const ms = crashes.restartMs.slice(3).sort((x, y) => x - y)
console.error(` first starts at most ${base} ms, later p50 ${ms[ms.length >> 1]} ms, max ${ms.at(-1)} ms, the last ${last} ms`)
const p50 = (xs) => [...xs].sort((x, y) => x - y)[xs.length >> 1]
const [ms, empty] = [starts.map((s) => s.ms), starts.map((s) => s.empty)]
console.error(` ${starts.length} starts, p50 ${p50(ms)} ms, max ${Math.max(...ms)} ms, the last ${ms.at(-1)} ms; the empty starts around each, their median p50 ${p50(empty)} ms, max ${Math.max(...empty)} ms`)
console.error(` ${crashes.count} crashes, ${crashes.reorganizing} while reorganizing, ${crashes.inFlight} with a write on its way (${crashes.landed} landed)`)
for (const [kind, { ok, error }] of Object.entries(counts).sort()) console.error(` ${kind.padEnd(56)} ${String(ok).padStart(5)} ok ${String(error).padStart(5)} refused`)
await shutdown(0)
spec/STORE.md+13−7
@@ -147,7 +147,8 @@ bucket holds what `BLOBS.md` says.
- **Starting.** The time to start does not grow with the number of
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 took to start on an empty one, plus 250 ms.
within twice the time it takes to start on an empty one, on the same
machine and under the same load, plus 250 ms.
An account's state may be read from disk on its first use after that
(below).
@@ -230,8 +231,8 @@ part of one.
both sides with `PDS_REPO_BACKFILL_LIMIT_MS=5000`, the reference's
`repoBackfillLimitMs` too, makes four accounts, each with a memberspace, and
fills each with records of 8 to 24 KB, at sixteen keys; then kills and
starts the server again three times, the slowest of those starts the first
start's time. Then it churns, on random accounts:
starts the server again three times, each start held to the bound above as
a crash's is (below). Then it churns, on random accounts:
- rewrites of those keys, alone and in batches, and deletes of them, each
compared with the reference as `REPO.md` says;
@@ -272,7 +273,12 @@ milliseconds later; if none comes in 200 writes, it kills it as
`DURABILITY.md`'s crashes do, sometimes with a write on its way. Then it
checks what those crashes check, the space repos, takedowns and preferences
too, with the firehose carrying on from its last event; and the start must
answer within the bound above of the first.
answer within the bound above. The harness times it among starts of the
same server on empty data directories, each of its own and on a port of
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.
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,
@@ -289,9 +295,9 @@ records 16 times, well within `2 W`; lets the data directory settle,
shuts the server down and starts it again, and, nothing else asked of the
server, sends that account a `getRecord`: the server must read no more
than 6 MiB to answer it. It deletes those records after. Then the server is
killed and started once more, the start timed, and every account checked
again. The run reports the data directory's size against the accounts' live
states, and the starts' times.
killed and started once more, the start held to the bound so, and every
account checked again. The run reports the data directory's size against
the accounts' live states, and the starts' times.
`node compare.mjs --scale ...` is a run of its own, of the server alone, as
the reference says nothing of its memory, with `PDS_CACHE_BYTES` 16 MiB. It