forked from mtusi2026/mtusi2026lab2
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
"""date: 2026-11-06T08:23:20.665782+00:00 commit: b063c8780eabf63cdb9da3802f82440750308d6b"""
|
|
|
|
import json
|
|
import pathlib
|
|
import statistics
|
|
import sys
|
|
import time
|
|
|
|
root = pathlib.Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(root / "student-tests"))
|
|
sys.path.insert(0, str(root / "scripts"))
|
|
from stand import valkey
|
|
from probe import actor, call
|
|
|
|
owner = actor("cache_latency")
|
|
rows = []
|
|
for repeat in range(30):
|
|
assert valkey("FLUSHALL") == "OK"
|
|
row = {"repeat": repeat + 1}
|
|
for mode in ["cold", "warm"]:
|
|
start = time.perf_counter()
|
|
status, instance, _ = call("GET", "/api/v1/users/me", headers=owner["auth"])
|
|
row[mode + "_ms"] = round((time.perf_counter() - start) * 1000, 3)
|
|
row[mode + "_instance"] = instance
|
|
assert status == 200
|
|
rows.append(row)
|
|
summary = {
|
|
mode + "_median_ms": statistics.median(row[mode + "_ms"] for row in rows)
|
|
for mode in ["cold", "warm"]
|
|
}
|
|
print(json.dumps({"samples": rows, "summary": summary, "pass": True}, indent=2))
|