Files

88 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Record the Phase 4 service-latency result into the append-only ledger,
mechanically from the measured JSON — no hand-typed numbers.
The p50 latency speedup (baseline/candidate) is a service-time speedup: at
a fixed arrival rate a faster worker serves the same load with fewer
cores, so it maps to the same throughput→cores→dollars ROI. We store it
as the row's speedup (with its CI) and keep the full percentile detail in
the env_fingerprint, so `report` renders both from one row.
python3 scripts/phase4-record.py <service.json> <run_id> <target_commit>
"""
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path("/home/user/peltier.io")
svc = json.load(open(sys.argv[1]))
run_id = sys.argv[2]
target_commit = sys.argv[3] if len(sys.argv) > 3 else ""
# p50 is the stable, service-time-tracking metric; use it as the row's
# headline speedup. p99 (noisier tail) is carried in the fingerprint.
p50_med = svc["p50_speedup_median"]
p50_ci = svc["p50_speedup_ci"]
attempt = {
"run_id": run_id,
"timestamp": subprocess.check_output(["date", "-u", "+%Y-%m-%dT%H:%M:%SZ"]).decode().strip(),
"target": "cjson",
"target_commit": target_commit,
"phase": 4,
"hotspot": "cJSON parse+print under HTTP load (service mode)",
"playbook_class": 5,
"hypothesis": (
"The accepted batch win phase3-cjson-002 (stack-buffer number parse + strtod "
"round-trip) reduces per-request service time; under a coordinated-omission-correct "
"open-loop replay it should show as a latency-percentile improvement, and the p50 "
"service-time speedup maps to throughput->cores->dollars ROI."
),
"patch": "(measurement of the already-accepted phase3-cjson-002 win under replayed load; no new code)",
"gates": {
"upstream_tests": True,
"golden_replay": True,
"fuzz_iters": 0,
"fuzz_divergence": False,
"sanitizers_clean": True,
},
"bench": {
"baseline_median": svc["baseline_p50_ms_median"] / 1e3,
"baseline_ci": [0.0, 0.0],
"candidate_median": svc["candidate_p50_ms_median"] / 1e3,
"candidate_ci": [0.0, 0.0],
"speedup_median": p50_med,
"speedup_ci": p50_ci,
"env_fingerprint": {
"workload": svc["workload"],
"metric": "p50 service latency (baseline/candidate), CO-correct open-loop replay",
"p50_speedup_median": p50_med,
"p50_speedup_ci": p50_ci,
"p99_speedup_median": svc["p99_speedup_median"],
"p99_speedup_ci": svc["p99_speedup_ci"],
"baseline_p50_ms": svc["baseline_p50_ms_median"],
"candidate_p50_ms": svc["candidate_p50_ms_median"],
"baseline_p99_ms": svc["baseline_p99_ms_median"],
"candidate_p99_ms": svc["candidate_p99_ms_median"],
"rate_rps": svc["rate_rps"],
"sessions": svc["sessions"],
"drop_rate": svc["drop_rate"],
"gates_detail": "latency measurement of the ASan/UBSan+fuzz-verified phase3-cjson-002 win",
},
},
"verdict": "accepted",
"tokens_spent": 0,
"wall_time_s": 0.0,
}
out = subprocess.run(
["cargo", "run", "-q", "-p", "ledger", "--bin", "ledger-cli", "--", str(ROOT / "results/ledger.sqlite")],
input=json.dumps(attempt), text=True, cwd=ROOT, capture_output=True,
)
print(out.stdout.strip())
if out.returncode != 0:
print(out.stderr, file=sys.stderr)
sys.exit(out.returncode)