лаба на 5
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
|
||||
import json
|
||||
import statistics
|
||||
from pathlib import Path
|
||||
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
ROOT = Path("evidence/scale")
|
||||
OUTPUT = ROOT / "charts"
|
||||
|
||||
THIRD_RUN = {
|
||||
1: "repeat2",
|
||||
2: "repeat2",
|
||||
4: "diagnostics",
|
||||
}
|
||||
|
||||
OUTPUT.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
summary = []
|
||||
|
||||
for replicas in (1, 2, 4):
|
||||
files = [
|
||||
ROOT / f"replicas-{replicas}-c16.json",
|
||||
ROOT / f"replicas-{replicas}-c16-repeat.json",
|
||||
ROOT / f"replicas-{replicas}-c16-{THIRD_RUN[replicas]}.json",
|
||||
]
|
||||
|
||||
results = [json.loads(path.read_text(encoding="utf-8")) for path in files]
|
||||
|
||||
rps = [result["successful_rps"] for result in results]
|
||||
p95 = [result["successful_latency_ms"]["p95"] for result in results]
|
||||
p99 = [result["successful_latency_ms"]["p99"] for result in results]
|
||||
errors = sum(result["failed_requests"] for result in results)
|
||||
|
||||
item = {
|
||||
"replicas": replicas,
|
||||
"rps_mean": statistics.mean(rps),
|
||||
"rps_std": statistics.stdev(rps),
|
||||
"p95_mean": statistics.mean(p95),
|
||||
"p99_mean": statistics.mean(p99),
|
||||
"errors": errors,
|
||||
}
|
||||
|
||||
summary.append(item)
|
||||
|
||||
print(f"\nРеплик: {replicas}")
|
||||
print(f"RPS: {', '.join(f'{value:.3f}' for value in rps)}")
|
||||
print(f"Средний RPS: {item['rps_mean']:.3f}")
|
||||
print(f"Стандартное отклонение RPS: {item['rps_std']:.3f}")
|
||||
print(f"Средний p95: {item['p95_mean']:.3f} мс")
|
||||
print(f"Средний p99: {item['p99_mean']:.3f} мс")
|
||||
print(f"Ошибок: {errors}")
|
||||
|
||||
replicas = [item["replicas"] for item in summary]
|
||||
rps_means = [item["rps_mean"] for item in summary]
|
||||
rps_stds = [item["rps_std"] for item in summary]
|
||||
p95_means = [item["p95_mean"] for item in summary]
|
||||
p99_means = [item["p99_mean"] for item in summary]
|
||||
|
||||
fig, ax = plt.subplots(figsize=(8, 5))
|
||||
ax.bar(replicas, rps_means, yerr=rps_stds, capsize=6)
|
||||
ax.set_xticks(replicas)
|
||||
ax.set_xlabel("API replicas")
|
||||
ax.set_ylabel("Successful requests per second")
|
||||
ax.set_title("Throughput at 16 concurrent clients")
|
||||
ax.grid(axis="y", alpha=0.3)
|
||||
fig.tight_layout()
|
||||
fig.savefig(OUTPUT / "throughput.png", dpi=160)
|
||||
plt.close(fig)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(8, 5))
|
||||
positions = list(range(len(replicas)))
|
||||
width = 0.35
|
||||
|
||||
ax.bar([x - width / 2 for x in positions], p95_means, width, label="p95")
|
||||
ax.bar([x + width / 2 for x in positions], p99_means, width, label="p99")
|
||||
ax.set_xticks(positions, replicas)
|
||||
ax.set_xlabel("API replicas")
|
||||
ax.set_ylabel("Latency (ms)")
|
||||
ax.set_title("Mean latency percentiles at 16 concurrent clients")
|
||||
ax.legend()
|
||||
ax.grid(axis="y", alpha=0.3)
|
||||
fig.tight_layout()
|
||||
fig.savefig(OUTPUT / "latency.png", dpi=160)
|
||||
plt.close(fig)
|
||||
|
||||
print(f"\nГрафики сохранены в {OUTPUT}")
|
||||
Reference in New Issue
Block a user