Files
mtusi2026lab2/tools/summarize_upload_memory.py
T
Artyom 12db77133f Forward the lab 5 foundation while preserving lab 6 telemetry
Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files.

Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
2026-11-06 12:29:35 +03:00

51 lines
2.0 KiB
Python

import argparse
import json
import statistics
from collections import defaultdict
from pathlib import Path
REPEATS = 3
def spread(values: list[float]) -> dict[str, float]:
return {"median": statistics.median(values), "min": min(values), "max": max(values)}
def main() -> None:
parser = argparse.ArgumentParser(description="Summarize three independent upload memory runs")
parser.add_argument("root", type=Path)
args = parser.parse_args()
groups = defaultdict(list)
for path in sorted(args.root.glob("run*/slots*.json")):
run = json.loads(path.read_text())
key = (run["upload_concurrency"], round(run["body_bytes"] / 1048576), run["concurrency"])
groups[key].append((path, run))
expected = {(s, m, c) for s in (3, 64) for m in (1, 10) for c in (10, 20, 40)}
if set(groups) != expected or any(len(runs) != REPEATS for runs in groups.values()):
parser.error("expected 12 points with three repeats each")
summary = []
for (slots, size, concurrency), rows in sorted(groups.items()):
runs = [r for _, r in rows]
summary.append(
{
"slots": slots,
"mib": size,
"concurrency": concurrency,
"files": [str(p.relative_to(args.root)) for p, _ in rows],
"commits": sorted({r["commit"] for r in runs}),
"status_codes": [r["status_codes"] for r in runs],
"api_peak_mib": spread(
[max(m["cgroup_memory_peak_mib"] for m in r["memory"].values()) for r in runs]
),
"lb_peak_mib": spread([r["lb"]["cgroup_memory_peak_mib"] for r in runs]),
"p95_ms": spread([r["latency_ms"]["p95"] for r in runs]),
"api_oom": sum(m["oom_kill"] for r in runs for m in r["memory"].values()),
"lb_oom": sum(r["lb"]["oom_kill"] for r in runs),
}
)
print(json.dumps(summary, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()