Versions 121 to 318
new file, 87 lines
1+// A local project's store lock under load: 1, 4 and 16 writers pushing to one local project at once. 3+// node scripts/local-writers.ts [writers ...] (default: 1 4 16; PUSHES=10 pushes per writer) 5+// Each writer is its own agent, in its own folder, changing its own file, so nothing collides: what's measured is the 6+// store's lock (one SQLite write transaction per call). Every push is its own `node client/abso.ts push` process, as 7+// an agent runs it. It prints each push's wall time (median, 95th percentile, slowest), the pushes per second across 8+// all writers, and any push that failed. 10+import { spawn } from "node:child_process"; 11+import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; 12+import { tmpdir } from "node:os"; 13+import { join, resolve } from "node:path"; 14+import { fileURLToPath } from "node:url"; 15+import { main } from "../client/src/main.ts"; 17+const ROOT = resolve(fileURLToPath(new URL("..", import.meta.url))); 18+const ENTRY = join(ROOT, "client", "abso.ts"); 19+const PUSHES = Number(process.env.PUSHES ?? 10); 20+const counts = process.argv.slice(2).map(Number); 22+function push(cwd: string, store: string, message: string): Promise<{ ms: number; ok: boolean; out: string }> { 23+ const started = performance.now(); 24+ return new Promise((done) => { 25+ const child = spawn(process.execPath, [ENTRY, "push", "-m", message], { 27+ env: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" }, 30+ child.stdout.on("data", (d) => { 33+ child.stderr.on("data", (d) => { 36+ child.on("close", (code) => done({ ms: performance.now() - started, ok: code === 0, out })); 40+const pct = (sorted: number[], p: number) => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))]!; 41+console.log(`Node ${process.versions.node}, ${PUSHES} pushes per writer, each writer its own agent and file.`); 42+console.log("writers | pushes | median | p95 | slowest | pushes/s | failed"); 43+for (const writers of counts.length > 0 ? counts : [1, 4, 16]) { 44+ const store = mkdtempSync(join(tmpdir(), "abso-writers-store-")); 45+ const folders: string[] = []; 46+ const env = { ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" }; 47+ const first = mkdtempSync(join(tmpdir(), "abso-writers-w0-")); 48+ writeFileSync(join(first, "readme.txt"), "writers\n"); 49+ const init = await main(["init", "--local", "--project", "writers", "--agent", "w0", "--as-is"], { 54+ if (init.exit !== 0) throw new Error(init.stdout + init.stderr); 56+ for (let w = 1; w < writers; w++) { 57+ const dir = mkdtempSync(join(tmpdir(), `abso-writers-w${w}-`)); 58+ const joined = await main(["join", "writers", "--local", "--agent", `w${w}`, "--dir", dir], { 63+ if (joined.exit !== 0) throw new Error(joined.stdout + joined.stderr); 66+ const times: number[] = []; 67+ const failures: string[] = []; 68+ const started = performance.now(); 70+ folders.map(async (dir, w) => { 71+ for (let i = 0; i < PUSHES; i++) { 72+ writeFileSync(join(dir, `w${w}.txt`), `writer ${w}, push ${i}\n`); 73+ const r = await push(dir, store, `w${w} push ${i}`); 75+ if (!r.ok) failures.push(`w${w} push ${i}: ${r.out.trim().split("\n").slice(-2).join(" / ")}`); 79+ const total = (performance.now() - started) / 1000; 80+ times.sort((a, b) => a - b); 81+ const ms = (n: number) => `${n.toFixed(0)} ms`.padStart(8); 83+ `${String(writers).padStart(7)} | ${String(times.length).padStart(6)} | ${ms(pct(times, 0.5))} | ${ms(pct(times, 0.95))} | ${ms(times.at(-1)!)} | ${(times.length / total).toFixed(1).padStart(8)} | ${failures.length}`, 85+ for (const f of failures.slice(0, 5)) console.log(` ${f}`); 86+ for (const d of [store, ...folders]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });