The simulator showed libp2p's default cap (about 190 on 16 GB) stranding newcomers on a bootstrap node: 12 of 200 and 212 of 400 nodes never found a peer. As shipped, the same networks now form and deliver 100% up to 600 nodes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
103 lines
4.5 KiB
JavaScript
103 lines
4.5 KiB
JavaScript
// Turns the JSON files of scripts/sim-sweep.sh (and allmende-sim -json) into
|
|
// the tables the graphs are drawn from: .tmp/sim/data/{scaling,timeline,phases,arrival}.json
|
|
//
|
|
// node scripts/sim-report.mjs [dir] # default dir: .tmp/sim
|
|
import { readdirSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const dir = process.argv[2] ?? ".tmp/sim";
|
|
const out = join(dir, "data");
|
|
mkdirSync(out, { recursive: true });
|
|
|
|
const pct = (ms, q) => (ms.length ? ms[Math.min(ms.length - 1, Math.floor(q * ms.length))] : null);
|
|
const r1 = (x) => (x == null ? null : Math.round(x * 10) / 10);
|
|
|
|
const runs = readdirSync(dir)
|
|
.filter((f) => f.endsWith(".json"))
|
|
.map((f) => ({ name: f.replace(/\.json$/, ""), ...JSON.parse(readFileSync(join(dir, f), "utf8")) }))
|
|
.sort((a, b) => a.meta.nodes - b.meta.nodes);
|
|
|
|
const scaling = [];
|
|
for (const r of runs) {
|
|
const m = r.meta;
|
|
const s = r.samples;
|
|
const last = s[s.length - 1] ?? {};
|
|
// a series nothing arrived in has no list of times (null)
|
|
const get = (k) => ({ sent: 0, ...r.series[k], ms: r.series[k]?.ms ?? [] });
|
|
const lst = get("listing");
|
|
const msg = get("message");
|
|
const rep = get("report");
|
|
const rej = get("rejoin");
|
|
const alone = /(\d+) of them have no peer at all/.exec(m.mesh ?? "");
|
|
scaling.push({
|
|
run: r.name,
|
|
limit: m.seed_conns < 0 ? "libp2p default" : "fixed",
|
|
nodes: m.nodes,
|
|
mesh_s: r1(m.mesh_s),
|
|
mesh_complete: m.mesh_complete,
|
|
nodes_without_peers: alone ? Number(alone[1]) : 0,
|
|
listing_delivered_pct: lst.sent ? r1((100 * lst.ms.length) / lst.sent) : null,
|
|
listing_p50_ms: r1(pct(lst.ms, 0.5)),
|
|
listing_p95_ms: r1(pct(lst.ms, 0.95)),
|
|
listing_p99_ms: r1(pct(lst.ms, 0.99)),
|
|
message_delivered_pct: msg.sent ? r1((100 * msg.ms.length) / msg.sent) : null,
|
|
message_p95_ms: r1(pct(msg.ms, 0.95)),
|
|
report_delivered_pct: rep.sent ? r1((100 * rep.ms.length) / rep.sent) : null,
|
|
report_p95_ms: r1(pct(rep.ms, 0.95)),
|
|
rejoin_p95_ms: r1(pct(rej.ms, 0.95)),
|
|
agreed: /identical listings/.test(m.agreement ?? ""),
|
|
heap_peak_mb: r1(Math.max(0, ...s.map((x) => x.heap_mb))),
|
|
goroutines_peak: Math.max(0, ...s.map((x) => x.goroutines)),
|
|
cpu_seconds: r1(last.cpu_s),
|
|
traffic_mb: r1(last.sent_mb),
|
|
traffic_kb_per_node: last.sent_mb ? r1((last.sent_mb * 1024) / m.nodes) : null,
|
|
duration_s: r1(last.t),
|
|
});
|
|
}
|
|
writeFileSync(join(out, "scaling.json"), JSON.stringify(scaling));
|
|
|
|
// per-second series of the runs worth looking at over time: the smallest, a middle one and the largest of each limit
|
|
const pick = new Set();
|
|
for (const limit of ["fixed", "libp2p default"]) {
|
|
const rs = scaling.filter((x) => x.limit === limit);
|
|
if (rs.length) {
|
|
pick.add(rs[0].run);
|
|
pick.add(rs[Math.floor(rs.length / 2)].run);
|
|
pick.add(rs[rs.length - 1].run);
|
|
}
|
|
}
|
|
const timeline = [];
|
|
const phases = [];
|
|
for (const r of runs.filter((x) => pick.has(x.name))) {
|
|
const s = r.samples;
|
|
for (let i = 0; i < s.length; i++) {
|
|
const dt = i ? s[i].t - s[i - 1].t : 1;
|
|
timeline.push({
|
|
run: r.name,
|
|
t: r1(s[i].t),
|
|
heap_mb: r1(s[i].heap_mb),
|
|
goroutines: s[i].goroutines,
|
|
cpu_cores: i ? r1((s[i].cpu_s - s[i - 1].cpu_s) / dt) : 0,
|
|
sent_mb_per_s: i ? Math.round(((s[i].sent_mb - s[i - 1].sent_mb) / dt) * 100) / 100 : 0,
|
|
});
|
|
}
|
|
for (const p of r.phases) phases.push({ run: r.name, name: p.name, from: r1(p.from), to: r1(p.to) });
|
|
}
|
|
writeFileSync(join(out, "timeline.json"), JSON.stringify(timeline));
|
|
writeFileSync(join(out, "phases.json"), JSON.stringify(phases));
|
|
|
|
// how listings arrive: the share of deliveries done after x milliseconds, 40 points per run
|
|
const arrival = [];
|
|
for (const r of runs) {
|
|
const lst = r.series.listing;
|
|
if (!lst || !lst.ms?.length) continue;
|
|
for (let i = 1; i <= 40; i++) {
|
|
const q = i / 40;
|
|
arrival.push({ run: r.name, nodes: r.meta.nodes, limit: r.meta.seed_conns < 0 ? "libp2p default" : "fixed", ms: r1(pct(lst.ms, q - 1e-9)), share: Math.round(((q * lst.ms.length) / lst.sent) * 1000) / 10 });
|
|
}
|
|
}
|
|
writeFileSync(join(out, "arrival.json"), JSON.stringify(arrival));
|
|
|
|
console.log(`${runs.length} runs: scaling ${scaling.length} rows, timeline ${timeline.length} rows (${[...pick].join(", ")}), arrival ${arrival.length} rows`);
|
|
console.table(scaling.map((x) => ({ run: x.run, mesh_s: x.mesh_s, ok: x.mesh_complete, alone: x.nodes_without_peers, lst_pct: x.listing_delivered_pct, lst_p95: x.listing_p95_ms, heapMB: x.heap_peak_mb, gor: x.goroutines_peak, cpu_s: x.cpu_seconds, kb_node: x.traffic_kb_per_node })));
|