Files
agentic-kvc/scripts/legacy/compare_balanced.py
Gahow Wang 547611e022 scripts: archive obsolete one-off shell/python scripts to legacy/ (D2, D3)
D2: run_benchmark.sh and run_experiments.sh still pass --time-scale and
--max-inflight-sessions to the replayer, but those flags were removed when
the project moved to trace-driven dispatch. The scripts cannot run as-is.

D3: ~25 ad-hoc analyze_* / compare_* / profile_* / final_* scripts and a
handful of single-experiment run_*.sh point at /home/admin/cpfs paths,
deleted output directories, or a sampled trace file that no longer exists.
Keep them in scripts/legacy/ for historical reference; the scripts that
remain in scripts/ (analyze_trace, analyze_breakdown, analyze_cache_hit,
analyze_eviction, compare_results, compute_roofline, sample_trace,
analyze_agentic_patterns, simulate_cache_policies, plus launch_*.sh,
gpu_monitor.sh, bench.sh) cover the current workflow.

Adds scripts/legacy/README.md to document the archival policy.
2026-05-23 20:57:32 +08:00

51 lines
1.8 KiB
Python

"""Compare balanced session-sticky routing vs old cache-aware baseline."""
import json
def stats(path):
rows = [json.loads(l) for l in open(path)]
ok = [r for r in rows if not r.get("error")]
ttfts = sorted([r["ttft_s"] for r in ok if r.get("ttft_s")])
tpots = sorted([r["tpot_s"] for r in ok if r.get("tpot_s") and r["tpot_s"]>0])
lats = sorted([r["latency_s"] for r in ok])
p = lambda v,q: v[min(int(q*len(v)),len(v)-1)] if v else 0
return {"ok": len(ok), "n": len(rows),
"t50": p(ttfts,.5), "t90": p(ttfts,.9),
"p50": p(tpots,.5), "p90": p(tpots,.9),
"e50": p(lats,.5), "e90": p(lats,.9)}
b = stats("outputs/exp2_combined_tp1_dp8/metrics.jsonl")
n = stats("outputs/balanced_routing/metrics.jsonl")
print("BALANCED ROUTING vs BASELINE")
print("Both: 1000 req, TP=1 DP=8 combined, cache-aware scheduler")
print("=" * 65)
fmt = "%-28s %7s %8s %8s %8s %8s"
print(fmt % ("Config", "OK/N", "TTFT50", "TTFT90", "TPOT90", "E2E50"))
print("-" * 65)
print(fmt % ("Old cache-aware",
"%d/%d" % (b["ok"], b["n"]),
"%.3f" % b["t50"], "%.3f" % b["t90"],
"%.3f" % b["p90"], "%.3f" % b["e50"]))
print(fmt % ("Balanced session-sticky",
"%d/%d" % (n["ok"], n["n"]),
"%.3f" % n["t50"], "%.3f" % n["t90"],
"%.3f" % n["p90"], "%.3f" % n["e50"]))
print()
print("APC:")
print(" Old cache-aware: 44.7%%")
print(" Balanced session-sticky: 48.7%% (+4.0pp)")
print(" Simulation prediction: 49.2%%")
print(" Theoretical (infinite): 51.0%%")
print()
print("DELTA:")
for label, bv, av in [
("TTFT p50", b["t50"], n["t50"]),
("TTFT p90", b["t90"], n["t90"]),
("TPOT p90", b["p90"], n["p90"]),
("E2E p50", b["e50"], n["e50"]),
]:
delta = (av/bv - 1) * 100 if bv > 0 else 0
print(" %s: %.3f -> %.3f (%+.1f%%)" % (label, bv, av, delta))