Harden request bounds and verify benchmark responses

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 12:30:42 +03:00
parent fbd5ec32f5
commit c9b15ba918
6 changed files with 96 additions and 66 deletions
+11 -8
View File
@@ -72,6 +72,7 @@ def seed_history(count, seed):
messages = [message for batch_result in pool.map(batch, range(8)) for message in batch_result]
messages.sort(key=lambda item: (item["created_at"], item["id"]))
midpoint = messages[count // 2]
expected_ids = [message["id"] for message in messages[count // 2 + 1:count // 2 + 21]]
cursor = base64.urlsafe_b64encode(json.dumps(
[f"messages:{chat}", midpoint["created_at"], midpoint["id"]], separators=(",", ":")
).encode()).decode().rstrip("=")
@@ -79,11 +80,11 @@ def seed_history(count, seed):
client = HTTP()
try:
page = client.call("GET", path, user)
assert len(page["items"]) == 20
assert [message["id"] for message in page["items"]] == expected_ids
assert (page["items"][0]["created_at"], page["items"][0]["id"]) > (midpoint["created_at"], midpoint["id"])
finally:
client.close()
return user, path
return user, path, expected_ids
def process_metrics():
@@ -97,7 +98,7 @@ def percentile(values, fraction):
return round(values[math.ceil(len(values) * fraction) - 1], 3) if values else ""
def load(user, path, clients, duration):
def load(user, path, expected_ids, clients, duration):
barrier = threading.Barrier(clients)
deadline = time.monotonic() + duration
@@ -109,9 +110,11 @@ def load(user, path, clients, duration):
while time.monotonic() < deadline:
start = time.perf_counter()
try:
connection.call("GET", path, user)
page = connection.call("GET", path, user)
if [message["id"] for message in page["items"]] != expected_ids:
raise ValueError("history page differs from seeded messages")
latencies.append((time.perf_counter() - start) * 1000)
except (OSError, RuntimeError, ValueError):
except (OSError, RuntimeError, ValueError, KeyError, TypeError):
errors += 1
connection.close()
connection = HTTP()
@@ -159,12 +162,12 @@ def main():
time.sleep(.1)
else:
raise RuntimeError("container did not become ready")
user, path = seed_history(history, args.seed)
user, path, expected_ids = seed_history(history, args.seed)
for clients in CLIENTS:
for repeat in range(1, args.repeats + 1):
load(user, path, clients, args.warmup)
load(user, path, expected_ids, clients, args.warmup)
cpu_before, rss_before = process_metrics()
elapsed, latencies, errors = load(user, path, clients, args.duration)
elapsed, latencies, errors = load(user, path, expected_ids, clients, args.duration)
cpu_after, rss_after = process_metrics()
total = len(latencies) + errors
row = dict(phase=args.phase, image=args.image, history=history, clients=clients,