forked from mtusi2026/mtusi2026lab3
Добавить парный эксперимент 8 против 12 реплик
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Rate-controlled paired scale test for 8 versus 12 API replicas."""
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import statistics
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import track1_experiment as bench
|
||||
from track1_offered_load import run_sample
|
||||
from client import Client
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
OUT = ROOT / "evidence"
|
||||
REPEATS = 3
|
||||
RATES = (1000,)
|
||||
REPLICAS = (8, 12)
|
||||
|
||||
|
||||
def main():
|
||||
OUT.mkdir(exist_ok=True)
|
||||
env = os.environ.copy()
|
||||
env.update(API_CPUS="0.5", API_MEMORY="256m", DB_POOL_MAX="10", LB_CPUS="0.25")
|
||||
bench.run(bench.COMPOSE + ["up", "-d", "--build", "--scale", "api=8", "--wait", "--wait-timeout", "180"], env)
|
||||
bench.wait_ready()
|
||||
time.sleep(5)
|
||||
client = Client("http://127.0.0.1:8080")
|
||||
actor, _, _, chat = client.bootstrap()
|
||||
rng = random.Random(20261107)
|
||||
samples = []
|
||||
last_replica_count = 8
|
||||
for repeat in range(1, REPEATS + 1):
|
||||
block = [(replicas, rate) for replicas in REPLICAS for rate in RATES]
|
||||
rng.shuffle(block)
|
||||
for replicas, rate in block:
|
||||
if last_replica_count != 8:
|
||||
bench.run(bench.COMPOSE + ["up", "-d", "--build", "--scale", "api=8", "--wait", "--wait-timeout", "180"], env)
|
||||
bench.wait_ready()
|
||||
time.sleep(5)
|
||||
last_replica_count = 8
|
||||
bench.reset_synthetic_messages()
|
||||
if replicas != last_replica_count:
|
||||
bench.run(bench.COMPOSE + ["up", "-d", "--build", "--scale", f"api={replicas}", "--wait", "--wait-timeout", "180"], env)
|
||||
bench.wait_ready()
|
||||
time.sleep(5)
|
||||
last_replica_count = replicas
|
||||
row = run_sample(actor, chat, rate, repeat, reset=False)
|
||||
row["replicas"] = replicas
|
||||
row["sample"] = repeat
|
||||
samples.append(row)
|
||||
print(json.dumps(row, ensure_ascii=False), flush=True)
|
||||
summary = []
|
||||
for replicas in REPLICAS:
|
||||
for rate in RATES:
|
||||
group = [r for r in samples if r["replicas"] == replicas and r["offered_rate_rps"] == rate]
|
||||
summary.append({
|
||||
"replicas": replicas,
|
||||
"offered_rate_rps": rate,
|
||||
"completed_success_rps_total_elapsed_median": round(statistics.median(r["completed_success_rps_total_elapsed"] for r in group), 3),
|
||||
"completed_success_rps_min": min(r["completed_success_rps_total_elapsed"] for r in group),
|
||||
"completed_success_rps_max": max(r["completed_success_rps_total_elapsed"] for r in group),
|
||||
"success_ratio_median": round(statistics.median(r["success_ratio"] for r in group), 6),
|
||||
"p95_ms_median": round(statistics.median(r["latency_successful_ms"]["p95"] for r in group), 3),
|
||||
"error_count_total": sum(r["failed_requests"] for r in group),
|
||||
"message_rows_after_median": int(statistics.median(r["message_rows_after"] for r in group if r["message_rows_after"] is not None)) if any(r["message_rows_after"] is not None for r in group) else None,
|
||||
})
|
||||
result = {
|
||||
"method": "Randomized paired blocks at offered 1000 RPS, 15s per sample; three repeats; compare 8 versus 12 replicas at fixed 0.5 CPU/256 MiB per API replica; DB_POOL_MAX=10, PostgreSQL 2 CPU/1 GiB, HAProxy 0.25 CPU; HAProxy server-template supports 16 backends; scale to 8 before each DB reset to release idle connections, then scale to target; synthetic messages and idempotency keys truncated per sample; HTTP client reused per worker.",
|
||||
"summary": summary,
|
||||
"samples": samples,
|
||||
}
|
||||
(OUT / "offered-scale-results.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user