Measure scaling cost and confirm two-replica operating point

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 13:59:18 +03:00
parent 23ed63f593
commit 750e56d0c6
13 changed files with 739 additions and 5 deletions
+72
View File
@@ -0,0 +1,72 @@
"""The scaling matrix must compare the same workload and resource budgets."""
import sys
import json
import unittest
from unittest.mock import patch
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
from benchmark import open_loop, topology, validate_matrix
class BenchmarkProfileTests(unittest.TestCase):
def test_fixed_budget_is_identical_across_replica_counts(self):
budgets = [topology("fixed", replicas) for replicas in (1, 2, 4)]
self.assertEqual([replicas * cpu for replicas, cpu, _ in budgets], [1.0] * 3)
self.assertEqual([replicas * memory for replicas, _, memory in budgets], [512] * 3)
def test_growth_budget_increases_with_replicas(self):
budgets = [topology("growth", replicas) for replicas in (1, 2, 4)]
self.assertEqual([replicas * cpu for replicas, cpu, _ in budgets], [0.5, 1.0, 2.0])
self.assertEqual([replicas * memory for replicas, _, memory in budgets], [256, 512, 1024])
def test_matrix_requires_three_repeats_and_same_workload(self):
rows = [
{"mode": mode, "replicas": replicas, "rate": rate, "repeat": repeat,
"duration": 8, "warmup": 2, "dataset_messages": 1000,
"api_cpu_each": topology(mode, replicas)[1],
"api_memory_mib_each": topology(mode, replicas)[2]}
for mode in ("fixed", "growth")
for replicas in (1, 2, 4)
for rate in (100, 250, 500)
for repeat in (1, 2, 3)
]
validate_matrix(rows)
with self.assertRaises(ValueError):
validate_matrix(rows[:-1])
rows[-1]["dataset_messages"] = 999
with self.assertRaises(ValueError):
validate_matrix(rows)
def test_open_loop_counts_responses_at_a_scheduled_rate(self):
class Response:
status = 200
def read(self):
return json.dumps({"items": [{}] * 20}).encode()
class Connection:
def __init__(self, *args, **kwargs):
pass
def request(self, *args, **kwargs):
pass
def getresponse(self):
return Response()
def close(self):
pass
with patch("benchmark.http.client.HTTPConnection", Connection):
result = open_loop("http://127.0.0.1:8080", "/history", "synthetic", 20, 0.2, workers=2)
self.assertEqual(result["scheduled_requests"], 4)
self.assertEqual(result["successful_requests"], 4)
self.assertEqual(result["failed_requests"], 0)
self.assertGreater(result["successful_latency_ms"]["p95"], 0)
if __name__ == "__main__":
unittest.main()