allmende-sim: record runs as JSON (samples, phases, arrival times); sweep script and graph data; scaling results
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
// 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 ? "lifted" : "libp2p default",
|
||||
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 ["lifted", "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 ? "lifted" : "libp2p default", 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 })));
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# How large a network can the protocol carry? Runs allmende-sim at growing sizes
|
||||
# and records every run as JSON in .tmp/sim/ (see scripts/sim-report.mjs for the graphs).
|
||||
#
|
||||
# scripts/sim-sweep.sh # the default sweep
|
||||
# SIZES="100 200" LIMITED="200" scripts/sim-sweep.sh
|
||||
#
|
||||
# SIZES run with the seeds' connection limit lifted; LIMITED run again with
|
||||
# libp2p's default limit (about 190 inbound connections on 16 GB of RAM).
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
OUT=.tmp/sim
|
||||
mkdir -p "$OUT"
|
||||
go build -o .tmp/allmende-sim ./cmd/allmende-sim || exit 1
|
||||
|
||||
SIZES=${SIZES:-"50 100 200 300 400 600 800"}
|
||||
LIMITED=${LIMITED:-"100 200 300 400"}
|
||||
|
||||
run() { # run NODES SEEDCONNS LABEL
|
||||
local n=$1 conns=$2 label=$3
|
||||
local regions=8; [ "$n" -lt 100 ] && regions=3
|
||||
echo "== $label: $n nodes, seed limit ${conns:-default}"
|
||||
.tmp/allmende-sim -nodes "$n" -regions $regions -seeds 3 -listings 30 -messages 20 -reports 3 -churn 0.1 \
|
||||
-timeout 60s ${conns:+-seed-conns $conns} -json "$OUT/$label.json" > "$OUT/$label.txt" 2>&1
|
||||
local code=$?
|
||||
grep "^ mesh\|^ listing\|^ report \|^ message " "$OUT/$label.txt" | cut -c1-200
|
||||
[ $code -ne 0 ] && echo " exit code $code (see $OUT/$label.txt)"
|
||||
return 0
|
||||
}
|
||||
|
||||
for n in $SIZES; do run "$n" 5000 "lifted-$n"; done
|
||||
for n in $LIMITED; do run "$n" "" "default-$n"; done
|
||||
echo "done: $(ls $OUT/*.json | wc -l) runs in $OUT"
|
||||
Reference in New Issue
Block a user