forked from mtusi2026/mtusi2026lab3
126 lines
4.6 KiB
Python
126 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
||
"""Графики трека 1 в формате open-loop."""
|
||
import csv
|
||
from pathlib import Path
|
||
import matplotlib
|
||
matplotlib.use('Agg')
|
||
import matplotlib.pyplot as plt
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
EVID = ROOT / 'evidence' / 'track1'
|
||
OUT = ROOT / 'evidence'
|
||
OUT.mkdir(exist_ok=True)
|
||
|
||
COLORS = {
|
||
'A1': '#1f77b4', 'A2': '#2ca02c', 'A4': '#d62728',
|
||
'B1': '#e377c2', 'B2': '#17becf', 'B4': '#ff7f0e',
|
||
}
|
||
|
||
# Читаем summary.csv (его пишет summarize-track1.py).
|
||
summary = ROOT / 'evidence' / 'track1-summary.csv'
|
||
rows = list(csv.DictReader(summary.open()))
|
||
|
||
|
||
def series(profile):
|
||
rs = sorted([r for r in rows if r['profile'] == profile],
|
||
key=lambda r: int(r['offered_rps']))
|
||
xs = [int(r['offered_rps']) for r in rs]
|
||
rps = [float(r['successful_rps']) for r in rs]
|
||
p95 = [float(r['p95_ms']) if r['p95_ms'] else 0.0 for r in rs]
|
||
err = [float(r['error_ratio_pct']) for r in rs]
|
||
return xs, rps, p95, err
|
||
|
||
|
||
def plot_pair(ax_rps, ax_p95, profiles, title):
|
||
for prof in profiles:
|
||
xs, rps, p95, err = series(prof)
|
||
if not xs:
|
||
continue
|
||
ax_rps.plot(xs, xs, linestyle=':', color='gray', linewidth=0.8, alpha=0.6)
|
||
ax_rps.plot(xs, rps, marker='o', color=COLORS[prof], label=prof)
|
||
ax_p95.plot(xs, p95, marker='o', color=COLORS[prof], label=prof)
|
||
|
||
ax_rps.set_xlabel('Offered requests / s')
|
||
ax_rps.set_ylabel('Successful responses / s')
|
||
ax_rps.set_title(title + ' — RPS')
|
||
ax_rps.grid(True)
|
||
ax_rps.legend()
|
||
|
||
ax_p95.set_xlabel('Offered requests / s')
|
||
ax_p95.set_ylabel('p95 latency, ms')
|
||
ax_p95.set_title(title + ' — p95')
|
||
ax_p95.axhline(y=500, linestyle='--', color='black', linewidth=0.8,
|
||
label='500 ms budget')
|
||
ax_p95.grid(True)
|
||
ax_p95.legend()
|
||
|
||
|
||
# ---------- A: fixed total ----------
|
||
fig, ax = plt.subplots(1, 2, figsize=(16, 6))
|
||
plot_pair(ax[0], ax[1], ['A1', 'A2', 'A4'],
|
||
'A: fixed total 1 CPU / 256M (1/2/4 реплики)')
|
||
fig.tight_layout()
|
||
fig.savefig(OUT / 'track1-A-fixed-total.png', dpi=140)
|
||
print('saved', OUT / 'track1-A-fixed-total.png')
|
||
|
||
|
||
# ---------- B: resources scale with replicas ----------
|
||
fig, ax = plt.subplots(1, 2, figsize=(16, 6))
|
||
plot_pair(ax[0], ax[1], ['B1', 'B2', 'B4'],
|
||
'B: 0.5 CPU / 128M на реплику (1/2/4 реплики = 0.5/1.0/2.0 CPU)')
|
||
fig.tight_layout()
|
||
fig.savefig(OUT / 'track1-B-scaling.png', dpi=140)
|
||
print('saved', OUT / 'track1-B-scaling.png')
|
||
|
||
|
||
# ---------- C: latency percentiles bar chart ----------
|
||
fig, ax = plt.subplots(figsize=(12, 5))
|
||
order = []
|
||
for prof in ['A1', 'A2', 'A4', 'B1', 'B2', 'B4']:
|
||
rs = sorted([r for r in rows if r['profile'] == prof],
|
||
key=lambda r: int(r['offered_rps']))
|
||
for r in rs:
|
||
order.append(r)
|
||
|
||
xs = list(range(len(order)))
|
||
width = 0.27
|
||
p50 = [float(r['p50_ms']) if r['p50_ms'] else 0.0 for r in order]
|
||
p95 = [float(r['p95_ms']) if r['p95_ms'] else 0.0 for r in order]
|
||
p99 = [float(r['p99_ms']) if r['p99_ms'] else 0.0 for r in order]
|
||
ax.bar([i - width for i in xs], p50, width=width, label='p50')
|
||
ax.bar(xs, p95, width=width, label='p95')
|
||
ax.bar([i + width for i in xs], p99, width=width, label='p99')
|
||
ax.set_xticks(xs)
|
||
ax.set_xticklabels(
|
||
[f"{r['profile']}-{r['offered_rps']}" for r in order],
|
||
rotation=60, ha='right', fontsize=7)
|
||
ax.set_ylabel('ms')
|
||
ax.set_title('Латентности p50/p95/p99 по профилям и offered RPS')
|
||
ax.grid(True, axis='y')
|
||
ax.legend()
|
||
fig.tight_layout()
|
||
fig.savefig(OUT / 'track1-C-latency-percentiles.png', dpi=140)
|
||
print('saved', OUT / 'track1-C-latency-percentiles.png')
|
||
|
||
|
||
# ---------- D: CPU split по профилям ----------
|
||
fig, ax = plt.subplots(figsize=(12, 5))
|
||
profiles = ['A1', 'A2', 'A4', 'B1', 'B2', 'B4']
|
||
for i, prof in enumerate(profiles):
|
||
rs = sorted([r for r in rows if r['profile'] == prof],
|
||
key=lambda r: int(r['offered_rps']))
|
||
xs = [i * 10 + j for j in range(len(rs))]
|
||
api_cpu = [float(r['api_cpu_sum_max']) for r in rs]
|
||
pg_cpu = [float(r['pg_cpu_max']) for r in rs]
|
||
lb_cpu = [float(r['lb_cpu_max']) for r in rs]
|
||
ax.plot(xs, api_cpu, marker='o', label=f'{prof} api sum', color=COLORS[prof])
|
||
ax.plot(xs, pg_cpu, marker='s', linestyle='--', color=COLORS[prof], alpha=0.6)
|
||
ax.plot(xs, lb_cpu, marker='^', linestyle=':', color=COLORS[prof], alpha=0.4)
|
||
ax.set_xlabel('profile × offered RPS')
|
||
ax.set_ylabel('CPU, cores')
|
||
ax.set_title('CPU split по профилям (точки — offered, линии — роли)')
|
||
ax.grid(True)
|
||
ax.legend(ncol=2, fontsize=8)
|
||
fig.tight_layout()
|
||
fig.savefig(OUT / 'track1-D-cpu-split.png', dpi=140)
|
||
print('saved', OUT / 'track1-D-cpu-split.png') |