sahiljagtap's picture
Drums launch benchmarks reproduction + paired Drums/Prime/E2B re-run (scrubbed)
4ef198a
Raw History Blame Contribute Delete
9.51 kB
"""analyze.py RAW_DIR: every table of the T2b report from the raw JSONL files only (T2's analysis, extended).
Files: RAW_DIR/<arm>-<w>.jsonl, arm in {old, new, rep-new}, w in {w1, w1p (t2prof.py), w2, w2a15 (t2load.py)}.
Prints markdown tables and writes RAW_DIR/../analysis.json."""
import json, math, os, random, sys
SEED = 20261110
B = 10000
def pct(v, p):
v = sorted(v)
if not v: return None
k = max(1, math.ceil(p / 100 * len(v)))
return v[k - 1]
def boot_ci(v, p, rnd):
if len(v) < 2: return (None, None)
n = len(v); est = []
for _ in range(B):
s = [v[rnd.randrange(n)] for _ in range(n)]
est.append(pct(s, p))
est.sort()
return (est[int(0.025 * B)], est[int(0.975 * B) - 1])
def ratio_ci(a, b, p, rnd):
if len(a) < 2 or len(b) < 2: return (None, None)
est = []
for _ in range(B):
sa = [a[rnd.randrange(len(a))] for _ in range(len(a))]
sb = [b[rnd.randrange(len(b))] for _ in range(len(b))]
est.append(pct(sa, p) / pct(sb, p))
est.sort()
return (est[int(0.025 * B)], est[int(0.975 * B) - 1])
def cp_upper(k, n, a=0.05):
# Clopper-Pearson upper bound via bisection on the binomial cdf
if n == 0: return None
if k == n: return 1.0
def cdf(p):
return sum(math.comb(n, i) * p**i * (1 - p)**(n - i) for i in range(k + 1))
lo, hi = k / n, 1.0
for _ in range(60):
m = (lo + hi) / 2
if cdf(m) > a / 2: lo = m
else: hi = m
return hi
def load(path):
return [json.loads(l) for l in open(path)] if os.path.exists(path) else []
def ops(R, kind, after_ramp):
ramp = next((r["epoch"] for r in R if r["kind"] == "ramped"), None) if after_ramp else None
xs = [r for r in R if r["kind"] == kind and (ramp is None or r.get("epoch", 0) >= ramp)]
if after_ramp and ramp is not None:
# an op counts when it STARTED after the ramp: epoch is written at the end, minus its wall time
xs = [r for r in R if r["kind"] == kind and r.get("epoch", 0) - r.get("wall_s", 0) >= ramp]
ok = [r["wall_s"] for r in xs if not r.get("error")]
inval = 0
for r in xs:
if r.get("error"): inval += (r.get("n") or 1) if kind == "fork" else 1
elif kind == "fork": inval += sum(1 for v in r.get("validity", []) if not v["valid"])
elif r.get("valid") is False: inval += 1
units = sum((r.get("n") or 1) for r in xs) if kind == "fork" else len(xs)
return ok, inval, units, xs
def main():
raw = sys.argv[1]
rnd = random.Random(SEED)
out = {"seed": SEED, "resamples": B, "rows": []}
bars = {"fork": (0.250, 0.600), "reset": (1.0, 2.0)}
print("| arm | workload | metric | N ok | p50 s [95% CI] | p95 s | p99 s [95% CI] | invalid / units (95% upper) | bar p50 | bar p99 |")
print("|---|---|---|---|---|---|---|---|---|---|")
data = {}
WS = ("w1", "w1p", "w2", "w2a15")
ARMS = ("old", "new", "rep-new")
for arm in ARMS:
for w in WS:
R = load(os.path.join(raw, f"{arm}-{w}.jsonl"))
if not R: continue
for kind in ("fork", "reset"):
ok, inval, units, xs = ops(R, kind, w.startswith("w2"))
if not xs: continue
data[(arm, w, kind)] = ok
c50 = boot_ci(ok, 50, rnd); c99 = boot_ci(ok, 99, rnd)
b50, b99 = bars[kind]
def verdict(ci, bar):
if ci[0] is None: return "n/a"
return "met" if ci[1] < bar else ("not met" if ci[0] > bar else "inconclusive")
row = {"arm": arm, "workload": w, "metric": kind, "n_ok": len(ok), "p50": pct(ok, 50), "p50_ci": c50, "p95": pct(ok, 95),
"p99": pct(ok, 99), "p99_ci": c99, "invalid": inval, "units": units, "invalid_upper95": cp_upper(inval, units),
"bar_p50": verdict(c50, b50), "bar_p99": verdict(c99, b99)}
out["rows"].append(row)
f = lambda x: "-" if x is None else f"{x:.3f}"
print(f"| {arm} | {w} | {kind} | {len(ok)} | {f(row['p50'])} [{f(c50[0])}, {f(c50[1])}] | {f(row['p95'])} | {f(row['p99'])} [{f(c99[0])}, {f(c99[1])}] | {inval} / {units} ({f(row['invalid_upper95'])}) | {row['bar_p50']} | {row['bar_p99']} |")
print()
print("| workload | metric | new/old p50 [95% CI] | new/old p99 [95% CI] |")
print("|---|---|---|---|")
for (o, n) in (("old", "new"),):
for w in WS:
for kind in ("fork", "reset"):
a, b = data.get((n, w, kind)), data.get((o, w, kind))
if not a or not b: continue
r50 = (pct(a, 50) / pct(b, 50), ratio_ci(a, b, 50, rnd)); r99 = (pct(a, 99) / pct(b, 99), ratio_ci(a, b, 99, rnd))
out["rows"].append({"ratio": f"{n}/{o}", "workload": w, "metric": kind, "p50_ratio": r50, "p99_ratio": r99})
print(f"| {w} ({n}/{o}) | {kind} | {r50[0]:.3f} [{r50[1][0]:.3f}, {r50[1][1]:.3f}] | {r99[0]:.3f} [{r99[1][0]:.3f}, {r99[1][1]:.3f}] |")
# where the time goes (W1, p50 of each term over the accepted capture attempt of every fork)
print()
print("| arm | quiescence wait | capture verb (dump) | dump check | adopt (server fill + hash) | capture total | children ready | child CRIU restore | fork wall | reset CRIU restore | reset task setup | reset wall |")
print("|---|---|---|---|---|---|---|---|---|---|---|---|")
for arm in ARMS:
R = load(os.path.join(raw, f"{arm}-w1.jsonl"))
F = [r for r in R if r["kind"] == "fork" and not r.get("error")]
S = [r for r in R if r["kind"] == "reset" and not r.get("error")]
if not F: continue
acc = {k: [] for k in ("wait", "dump", "check", "adopt", "cap", "kids", "kcriu", "wall", "rcriu", "rsetup", "rwall")}
for r in F:
a = (r.get("quiescence") or {}).get("attempts", [{}])[-1]
acc["wait"].append(sum(x.get("wait_s", 0) for x in r["quiescence"]["attempts"]))
acc["dump"].append(a.get("dump_s")); acc["check"].append(a.get("dump_check_s"))
acc["adopt"].append(a["source_check_after_s"] - a["dump_s"] if a.get("source_check_after_s") else None)
acc["cap"].append(r["server"]["capture_s"]); acc["kids"].append(r["server"]["children_ready_s"]); acc["wall"].append(r["wall_s"])
acc["kcriu"].extend((c.get("timings") or {}).get("criu_clock") for c in r["children"])
for r in S:
acc["rcriu"].append(r["timings"].get("criu_clock")); acc["rsetup"].append(r["timings"].get("task_setup")); acc["rwall"].append(r["wall_s"])
med = {k: pct([x for x in v if x is not None], 50) for k, v in acc.items()}
out.setdefault("phases", {})[arm] = med
f = lambda x: "-" if x is None else f"{x:.3f}"
print("| " + arm + " | " + " | ".join(f(med[k]) for k in ("wait", "dump", "check", "adopt", "cap", "kids", "kcriu", "wall", "rcriu", "rsetup", "rwall")) + " |")
# prefork (W1p): how many forks were served by the prefork, and the claim's own terms
print()
print("| arm | W1p forks | served by the prefork | prefork waited p50 s | hash check p50 s | prepare (capture + children) p50 s |")
print("|---|---|---|---|---|---|")
for arm in ARMS:
R = load(os.path.join(raw, f"{arm}-w1p.jsonl"))
F = [r for r in R if r["kind"] == "fork" and not r.get("error")]
if not F: continue
P = [(r["server"].get("prefork") or {}) for r in F]
C = [p for p in P if p.get("claimed")]
f = lambda x: "-" if x is None else f"{x:.3f}"
row = {"arm": arm, "forks": len(F), "claimed": len(C), "waited_p50": pct([p["waited_s"] for p in C], 50),
"hash_p50": pct([p["hash_check_s"] for p in C], 50), "prepare_p50": pct([p["prepare_seconds"] for p in C], 50)}
out.setdefault("prefork", {})[arm] = row
print(f"| {arm} | {len(F)} | {len(C)} | {f(row['waited_p50'])} | {f(row['hash_p50'])} | {f(row['prepare_p50'])} |")
# resets under load: per phase (p50 / p99) and the cost to the other envs (step latency)
print()
print("| arm | workload | resets | queue_wait | kill | restore (client) | CRIU restore | kernel gates | hash+isolation | task setup | total | step p50 / p99 |")
print("|---|---|---|---|---|---|---|---|---|---|---|---|")
for arm in ARMS:
for w in ("w2", "w2a15"):
R = load(os.path.join(raw, f"{arm}-{w}.jsonl"))
if not R: continue
_, _, _, xs = ops(R, "reset", True)
_, _, _, st = ops(R, "step", True)
xs = [r for r in xs if not r.get("error")]
if not xs: continue
ph = {}
for k in ("queue_wait", "kill", "restore", "criu_clock", "gates_kernel", "hash_isolation", "task_setup", "total"):
v = [r["timings"].get(k) for r in xs if (r.get("timings") or {}).get(k) is not None]
ph[k] = (pct(v, 50), pct(v, 99)) if v else (None, None)
sv = [r["wall_s"] for r in st if not r.get("error")]
out.setdefault("reset_phases", {})[f"{arm}-{w}"] = {**ph, "step": (pct(sv, 50), pct(sv, 99))}
f = lambda x: "-" if x is None else f"{x:.3f}"
cells = [f"{f(a)} / {f(b)}" for (a, b) in ph.values()]
print(f"| {arm} | {w} | {len(xs)} | " + " | ".join(cells) + f" | {f(pct(sv, 50))} / {f(pct(sv, 99))} |")
json.dump(out, open(os.path.join(raw, "..", "analysis.json"), "w"), indent=1, default=str)
if __name__ == "__main__":
main()