From 45fd5772ff7fd191f491c5850758f5e697c08653 Mon Sep 17 00:00:00 2001 From: koichakaev <52+koichakaev@noreply.gitea.privcloud.tech> Date: Fri, 6 Nov 2026 19:12:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=B0=D1=80=D0=BD=D1=8B=D0=B9=20=D1=8D=D0=BA?= =?UTF-8?q?=D1=81=D0=BF=D0=B5=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D1=82=208=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=82=D0=B8=D0=B2=2012=20=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=BB=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/track1_offered_scale.py | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 scripts/track1_offered_scale.py diff --git a/scripts/track1_offered_scale.py b/scripts/track1_offered_scale.py new file mode 100644 index 00000000..af408b5a --- /dev/null +++ b/scripts/track1_offered_scale.py @@ -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()