peppa/bench/sqlite/report.ts
Асель 50b1d1afec PEP-36: benchmark SQLite vs Postgres and propose Bun + SQLite stack
bench/sqlite (outside the workspace): Peppa-like load with 10/20 runners,
a hook process per event, MCP, bot, web and watchdog; bun:sqlite,
node:sqlite, better-sqlite3, a single-writer service and Postgres; notify
replacements (cursor polling, fs.watch on WAL, unix-socket push); a
ceiling test; a schema port to sqlite with a data copy from Postgres and
a check of drizzle transactions.

openspec/changes/pep-36-lightweight-stack: proposal, design with the
numbers, specs (platform-storage, service-monitoring), phased tasks.
No product code changes; the move waits for the PM's decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:28:59 +05:00

49 lines
3.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Markdown tables from results/*/summary.json: `node report.ts > results/report.md`.
import { readdirSync, readFileSync, existsSync } from "node:fs";
const dir = new URL("results/", import.meta.url).pathname;
const runs = readdirSync(dir)
.filter((d) => existsSync(`${dir}${d}/summary.json`))
.map((d) => JSON.parse(readFileSync(`${dir}${d}/summary.json`, "utf8")));
const order = ["bun", "node", "better", "writer", "pg"];
const label: Record<string, string> = { bun: "bun:sqlite", node: "node:sqlite", better: "better-sqlite3", writer: "один писатель (Bun)", pg: "Postgres (Node)" };
const f = (v: number) => (Number.isFinite(v) ? (v >= 100 ? v.toFixed(0) : v.toFixed(2)) : "—");
const row = (r: any, k: string) => r.rows[k] ?? { n: 0, p50: NaN, p95: NaN, p99: NaN, max: NaN, busy: 0, errors: 0 };
console.log("## Записи и доставка\n");
console.log("| раннеры | нагрузка | вариант | записей | p50 мс | p95 | p99 | max | BUSY-повторы | ошибки | хук целиком p50/p95 | старт хука p50 | доставка боту p50/p95/p99 |");
console.log("|---|---|---|---|---|---|---|---|---|---|---|---|---|");
for (const r of runs.filter((r) => r.notify === "pg" || r.notify === "poll:1000" || (r.backend === "writer" && r.notify === "push")).sort((a, b) => a.runners - b.runners || a.load - b.load || order.indexOf(a.backend) - order.indexOf(b.backend))) {
if (r.backend === "bun" && r.notify !== "poll:1000") continue;
const w = { ...row(r, "write ALL") };
// Runs before the fix counted hooks killed by the end-of-run SIGTERM as crashes.
if (r.errors.every((e: string) => e === "hook exited with null")) w.errors -= row(r, "write hook.crashed").errors;
const h = row(r, "total hook");
const s = row(r, "startup hook");
const d = row(r, "deliver bot");
console.log(`| ${r.runners} | ×${r.load} | ${label[r.backend]} | ${w.n} | ${f(w.p50)} | ${f(w.p95)} | ${f(w.p99)} | ${f(w.max)} | ${w.busy} | ${w.errors} | ${f(h.p50)} / ${f(h.p95)} | ${f(s.p50)} | ${f(d.p50)} / ${f(d.p95)} / ${f(d.p99)} (${r.notify}) |`);
}
console.log("\n## Замена LISTEN/NOTIFY (bun:sqlite, 20 раннеров, ×10)\n");
console.log("| способ | доставка боту p50 | p95 | p99 | max | веб p50 | p95 |");
console.log("|---|---|---|---|---|---|---|");
for (const r of runs.filter((r) => r.backend === "bun" && r.runners === 20 && r.load === 10)) {
const b = row(r, "deliver bot");
const w = row(r, "deliver web");
console.log(`| ${r.notify} | ${f(b.p50)} | ${f(b.p95)} | ${f(b.p99)} | ${f(b.max)} | ${f(w.p50)} | ${f(w.p95)} |`);
}
const pg = runs.find((r) => r.backend === "pg" && r.runners === 20 && r.load === 10);
if (pg) {
const b = row(pg, "deliver bot");
console.log(`| Postgres LISTEN/NOTIFY (для сравнения) | ${f(b.p50)} | ${f(b.p95)} | ${f(b.p99)} | ${f(b.max)} | ${f(row(pg, "deliver web").p50)} | ${f(row(pg, "deliver web").p95)} |`);
}
console.log("\n## Самые медленные операции записи (p99, мс) при 20 раннерах ×10\n");
console.log("| операция | " + order.map((b) => label[b]).join(" | ") + " |");
console.log("|---|" + order.map(() => "---|").join(""));
const at = (b: string) => runs.find((r) => r.backend === b && r.runners === 20 && r.load === 10 && (b !== "bun" || r.notify === "poll:1000"));
const ops = new Set<string>();
for (const b of order) for (const k of Object.keys(at(b)?.rows ?? {})) if (k.startsWith("write ") && k !== "write ALL" && k !== "write hook.crashed") ops.add(k);
for (const k of [...ops].sort()) console.log(`| ${k.slice(6)} | ` + order.map((b) => f(at(b)?.rows[k]?.p99 ?? NaN)).join(" | ") + " |");