Download this file
| 1 | #!/usr/bin/env python3 |
| 2 | """Server-side view of each probe run: per-request server time and the |
| 3 | request mix, from the probe server's events.jsonl and summary.jsonl. |
| 4 | |
| 5 | server-costs.py <run-probe out-dir> |
| 6 | """ |
| 7 | import json, math, sys |
| 8 | from pathlib import Path |
| 9 | |
| 10 | out = Path(sys.argv[1]) |
| 11 | events = [json.loads(l) for l in (out / "events.jsonl").open()] |
| 12 | def pct(xs, p): |
| 13 | s = sorted(xs) |
| 14 | return s[max(0, math.ceil(p * len(s)) - 1)] if s else float("nan") |
| 15 | print(f"{'run':22} {'POST/s':>7} {'GET/s':>6} {'SSE ev/s':>8} {'SSE B/s':>8} {'POST ms p50/p95':>16} {'GET ms p50/p95':>15} {'CPU ms/s':>9} {'CPU/POST':>9} {'alloc MB/s':>10} {'heap MB':>8}") |
| 16 | for line in (out / "summary.jsonl").open(): |
| 17 | s = json.loads(line) |
| 18 | t0, t1 = s["t0"], s["typed"] + 2000 |
| 19 | secs = (t1 - t0) / 1000 |
| 20 | win = [e for e in events if t0 <= e["t"] <= t1] |
| 21 | posts = [e["end"] - e["t"] for e in win if e["ev"] == "req" and e["method"] == "POST" and e["path"].endswith("/updates")] |
| 22 | gets = [e["end"] - e["t"] for e in win if e["ev"] == "req" and e["method"] == "GET" and "/updates?since" in e["path"]] |
| 23 | sse = [e for e in win if e["ev"] == "sse"] |
| 24 | cpu = s["server_cpu_ms"] |
| 25 | print(f"{s['label']:22} {len(posts)/secs:7.1f} {len(gets)/secs:6.1f} {len(sse)/secs:8.1f} {sum(e['bytes'] for e in sse)/secs:8.0f} " |
| 26 | f"{pct(posts,.5):7.1f}/{pct(posts,.95):<7.1f} {pct(gets,.5):6.1f}/{pct(gets,.95):<7.1f} {cpu/secs:9.0f} {cpu/max(1,len(posts)):9.1f} " |
| 27 | f"{s['server_alloc_mb']/secs:10.1f} {s['server_heap_inuse_mb']:8.0f}") |
| 28 | |