{"file":"scripts/local-writers.ts","version":318,"total":87,"from":1,"to":87,"lines":[{"n":1,"text":"// A local project's store lock under load: 1, 4 and 16 writers pushing to one local project at once.","atom":"a2835","author":"pinch","version":289},{"n":2,"text":"//","atom":"a2835","author":"pinch","version":289},{"n":3,"text":"//   node scripts/local-writers.ts [writers ...]        (default: 1 4 16; PUSHES=10 pushes per writer)","atom":"a2835","author":"pinch","version":289},{"n":4,"text":"//","atom":"a2835","author":"pinch","version":289},{"n":5,"text":"// Each writer is its own agent, in its own folder, changing its own file, so nothing collides: what's measured is the","atom":"a2835","author":"pinch","version":289},{"n":6,"text":"// store's lock (one SQLite write transaction per call). Every push is its own `node client/abso.ts push` process, as","atom":"a2835","author":"pinch","version":289},{"n":7,"text":"// an agent runs it. It prints each push's wall time (median, 95th percentile, slowest), the pushes per second across","atom":"a2835","author":"pinch","version":289},{"n":8,"text":"// all writers, and any push that failed.","atom":"a2835","author":"pinch","version":289},{"n":9,"text":"","atom":"a2835","author":"pinch","version":289},{"n":10,"text":"import { spawn } from \"node:child_process\";","atom":"a2835","author":"pinch","version":289},{"n":11,"text":"import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";","atom":"a2835","author":"pinch","version":289},{"n":12,"text":"import { tmpdir } from \"node:os\";","atom":"a2835","author":"pinch","version":289},{"n":13,"text":"import { join, resolve } from \"node:path\";","atom":"a2835","author":"pinch","version":289},{"n":14,"text":"import { fileURLToPath } from \"node:url\";","atom":"a2835","author":"pinch","version":289},{"n":15,"text":"import { main } from \"../client/src/main.ts\";","atom":"a2835","author":"pinch","version":289},{"n":16,"text":"","atom":"a2835","author":"pinch","version":289},{"n":17,"text":"const ROOT = resolve(fileURLToPath(new URL(\"..\", import.meta.url)));","atom":"a2835","author":"pinch","version":289},{"n":18,"text":"const ENTRY = join(ROOT, \"client\", \"abso.ts\");","atom":"a2835","author":"pinch","version":289},{"n":19,"text":"const PUSHES = Number(process.env.PUSHES ?? 10);","atom":"a2835","author":"pinch","version":289},{"n":20,"text":"const counts = process.argv.slice(2).map(Number);","atom":"a2835","author":"pinch","version":289},{"n":21,"text":"","atom":"a2835","author":"pinch","version":289},{"n":22,"text":"function push(cwd: string, store: string, message: string): Promise<{ ms: number; ok: boolean; out: string }> {","atom":"a2835","author":"pinch","version":289},{"n":23,"text":"\tconst started = performance.now();","atom":"a2835","author":"pinch","version":289},{"n":24,"text":"\treturn new Promise((done) => {","atom":"a2835","author":"pinch","version":289},{"n":25,"text":"\t\tconst child = spawn(process.execPath, [ENTRY, \"push\", \"-m\", message], {","atom":"a2835","author":"pinch","version":289},{"n":26,"text":"\t\t\tcwd,","atom":"a2835","author":"pinch","version":289},{"n":27,"text":"\t\t\tenv: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" },","atom":"a2835","author":"pinch","version":289},{"n":28,"text":"\t\t});","atom":"a2835","author":"pinch","version":289},{"n":29,"text":"\t\tlet out = \"\";","atom":"a2835","author":"pinch","version":289},{"n":30,"text":"\t\tchild.stdout.on(\"data\", (d) => {","atom":"a2835","author":"pinch","version":289},{"n":31,"text":"\t\t\tout += d;","atom":"a2835","author":"pinch","version":289},{"n":32,"text":"\t\t});","atom":"a2835","author":"pinch","version":289},{"n":33,"text":"\t\tchild.stderr.on(\"data\", (d) => {","atom":"a2835","author":"pinch","version":289},{"n":34,"text":"\t\t\tout += d;","atom":"a2835","author":"pinch","version":289},{"n":35,"text":"\t\t});","atom":"a2835","author":"pinch","version":289},{"n":36,"text":"\t\tchild.on(\"close\", (code) => done({ ms: performance.now() - started, ok: code === 0, out }));","atom":"a2835","author":"pinch","version":289},{"n":37,"text":"\t});","atom":"a2835","author":"pinch","version":289},{"n":38,"text":"}","atom":"a2835","author":"pinch","version":289},{"n":39,"text":"","atom":"a2835","author":"pinch","version":289},{"n":40,"text":"const pct = (sorted: number[], p: number) => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))]!;","atom":"a2835","author":"pinch","version":289},{"n":41,"text":"console.log(`Node ${process.versions.node}, ${PUSHES} pushes per writer, each writer its own agent and file.`);","atom":"a2835","author":"pinch","version":289},{"n":42,"text":"console.log(\"writers | pushes | median   | p95      | slowest  | pushes/s | failed\");","atom":"a2835","author":"pinch","version":289},{"n":43,"text":"for (const writers of counts.length > 0 ? counts : [1, 4, 16]) {","atom":"a2835","author":"pinch","version":289},{"n":44,"text":"\tconst store = mkdtempSync(join(tmpdir(), \"abso-writers-store-\"));","atom":"a2835","author":"pinch","version":289},{"n":45,"text":"\tconst folders: string[] = [];","atom":"a2835","author":"pinch","version":289},{"n":46,"text":"\tconst env = { ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" };","atom":"a2835","author":"pinch","version":289},{"n":47,"text":"\tconst first = mkdtempSync(join(tmpdir(), \"abso-writers-w0-\"));","atom":"a2835","author":"pinch","version":289},{"n":48,"text":"\twriteFileSync(join(first, \"readme.txt\"), \"writers\\n\");","atom":"a2835","author":"pinch","version":289},{"n":49,"text":"\tconst init = await main([\"init\", \"--local\", \"--project\", \"writers\", \"--agent\", \"w0\", \"--as-is\"], {","atom":"a2835","author":"pinch","version":289},{"n":50,"text":"\t\tcwd: first,","atom":"a2835","author":"pinch","version":289},{"n":51,"text":"\t\tenv,","atom":"a2835","author":"pinch","version":289},{"n":52,"text":"\t\twrite: () => {},","atom":"a2835","author":"pinch","version":289},{"n":53,"text":"\t});","atom":"a2835","author":"pinch","version":289},{"n":54,"text":"\tif (init.exit !== 0) throw new Error(init.stdout + init.stderr);","atom":"a2835","author":"pinch","version":289},{"n":55,"text":"\tfolders.push(first);","atom":"a2835","author":"pinch","version":289},{"n":56,"text":"\tfor (let w = 1; w < writers; w++) {","atom":"a2835","author":"pinch","version":289},{"n":57,"text":"\t\tconst dir = mkdtempSync(join(tmpdir(), `abso-writers-w${w}-`));","atom":"a2835","author":"pinch","version":289},{"n":58,"text":"\t\tconst joined = await main([\"join\", \"writers\", \"--local\", \"--agent\", `w${w}`, \"--dir\", dir], {","atom":"a2835","author":"pinch","version":289},{"n":59,"text":"\t\t\tcwd: dir,","atom":"a2835","author":"pinch","version":289},{"n":60,"text":"\t\t\tenv,","atom":"a2835","author":"pinch","version":289},{"n":61,"text":"\t\t\twrite: () => {},","atom":"a2835","author":"pinch","version":289},{"n":62,"text":"\t\t});","atom":"a2835","author":"pinch","version":289},{"n":63,"text":"\t\tif (joined.exit !== 0) throw new Error(joined.stdout + joined.stderr);","atom":"a2835","author":"pinch","version":289},{"n":64,"text":"\t\tfolders.push(dir);","atom":"a2835","author":"pinch","version":289},{"n":65,"text":"\t}","atom":"a2835","author":"pinch","version":289},{"n":66,"text":"\tconst times: number[] = [];","atom":"a2835","author":"pinch","version":289},{"n":67,"text":"\tconst failures: string[] = [];","atom":"a2835","author":"pinch","version":289},{"n":68,"text":"\tconst started = performance.now();","atom":"a2835","author":"pinch","version":289},{"n":69,"text":"\tawait Promise.all(","atom":"a2835","author":"pinch","version":289},{"n":70,"text":"\t\tfolders.map(async (dir, w) => {","atom":"a2835","author":"pinch","version":289},{"n":71,"text":"\t\t\tfor (let i = 0; i < PUSHES; i++) {","atom":"a2835","author":"pinch","version":289},{"n":72,"text":"\t\t\t\twriteFileSync(join(dir, `w${w}.txt`), `writer ${w}, push ${i}\\n`);","atom":"a2835","author":"pinch","version":289},{"n":73,"text":"\t\t\t\tconst r = await push(dir, store, `w${w} push ${i}`);","atom":"a2835","author":"pinch","version":289},{"n":74,"text":"\t\t\t\ttimes.push(r.ms);","atom":"a2835","author":"pinch","version":289},{"n":75,"text":"\t\t\t\tif (!r.ok) failures.push(`w${w} push ${i}: ${r.out.trim().split(\"\\n\").slice(-2).join(\" / \")}`);","atom":"a2835","author":"pinch","version":289},{"n":76,"text":"\t\t\t}","atom":"a2835","author":"pinch","version":289},{"n":77,"text":"\t\t}),","atom":"a2835","author":"pinch","version":289},{"n":78,"text":"\t);","atom":"a2835","author":"pinch","version":289},{"n":79,"text":"\tconst total = (performance.now() - started) / 1000;","atom":"a2835","author":"pinch","version":289},{"n":80,"text":"\ttimes.sort((a, b) => a - b);","atom":"a2835","author":"pinch","version":289},{"n":81,"text":"\tconst ms = (n: number) => `${n.toFixed(0)} ms`.padStart(8);","atom":"a2835","author":"pinch","version":289},{"n":82,"text":"\tconsole.log(","atom":"a2835","author":"pinch","version":289},{"n":83,"text":"\t\t`${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}`,","atom":"a2835","author":"pinch","version":289},{"n":84,"text":"\t);","atom":"a2835","author":"pinch","version":289},{"n":85,"text":"\tfor (const f of failures.slice(0, 5)) console.log(`        ${f}`);","atom":"a2835","author":"pinch","version":289},{"n":86,"text":"\tfor (const d of [store, ...folders]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });","atom":"a2835","author":"pinch","version":289},{"n":87,"text":"}","atom":"a2835","author":"pinch","version":289}],"atoms":[{"atom":"a2835","author":"pinch","message":"","time":1792120006171,"timeIso":"2026-10-16T03:06:46.171Z","publish":{"draft":null,"version":289,"agent":"pinch","message":"Local projects run as their own processes again: no compile cache for a local command, and plain words when the server's code can't load\n\nAt 287, every local command run as `node client/abso.ts` could crash with a segmentation fault (exit 139, at random, init and join included). The cause is Node's compile cache, which client/avcs.ts turns on, together with the module hook that gives the open server's code its cloudflare:workers stand-in. avcs.ts now leaves the cache off for a --local command and in a folder whose config names the server \"local\". The hook also stays registered rather than being removed after the import.\n\n- If the server's code can't load (a package missing, say), it's said as \"local projects couldn't load the server's code: ...\" rather than \"Can't reach local ... check your connection\".\n- In a local folder, status says \"It's a local project, in <store>/<project>.\" instead of \"Signed in with none.\", and skips the npm newer-client check, which reaches for the network.\n- worker/project/news.ts is Biome-formatted (only formatting), so the check gets past Biome again.\n- scripts/local-measure.ts times status, log, blame, pull and push as separate processes on a small and a large local history, with peak memory and the store's size. scripts/local-writers.ts pushes from 1, 4 and 16 writers at once to measure the store lock.\n\nTests: client/test/local.test.ts (9, one running init, push, status and log as child processes with the cache as it is); tsc and Biome clean. Three rounds of init, push and status as processes exit 0.","time":1792120394633,"timeIso":"2026-10-16T03:13:14.633Z"}}]}