-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_main.py
More file actions
264 lines (221 loc) · 9.47 KB
/
Copy pathplot_main.py
File metadata and controls
264 lines (221 loc) · 9.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python3
"""Render the main-campaign figures for thesis chapter 6.
Reads an aggregated results tree (the output of aggregate.py: a
<results>/summary/ directory with one CSV per metric plus long-format
runs.csv) and writes the core Ch. 6 figures as PDF (vector, for LaTeX) and
PNG (quick view).
Usage:
./plot_main.py [results_dir] [out_dir]
Defaults: results_dir=results/main, out_dir=<results_dir>/figures.
Tolerant by design: a figure whose cells are absent is skipped with a note,
so it runs against results/main_smoke before the full dataset exists. Cells
are addressed by (mechanism, scenario, sweep_label); load is the label.
"""
import csv
import sys
from collections import defaultdict
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
RESULTS = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("results/main")
SUMMARY = RESULTS / "summary"
OUTDIR = Path(sys.argv[2]) if len(sys.argv) > 2 else RESULTS / "figures"
STAT_FIELDS = ("n", "mean", "median", "p95", "std", "ci95_lo", "ci95_hi")
KEY = ("mechanism", "scenario", "sweep_label")
C_A, C_B = "#1f77b4", "#d62728"
C_IDLE, C_LOAD = "#1f77b4", "#ff7f0e"
C_OK, C_FAIL = "#2ca02c", "#d62728"
def _f(x):
try:
return float(x)
except (TypeError, ValueError):
return float("nan")
def load_metric(metric):
out = {}
path = SUMMARY / (metric + ".csv")
if not path.exists():
return out
with path.open() as fh:
for row in csv.DictReader(fh):
key = tuple(row[k] for k in KEY)
out[key] = {f: _f(row.get(f)) for f in STAT_FIELDS}
return out
def load_runs(metric):
out = defaultdict(list)
path = SUMMARY / "runs.csv"
if not path.exists():
return out
with path.open() as fh:
for row in csv.DictReader(fh):
if row["metric"] == metric:
out[tuple(row[k] for k in KEY)].append(_f(row["value"]))
return out
def ci_err(cell):
lo = max(0.0, cell["mean"] - cell["ci95_lo"])
hi = max(0.0, cell["ci95_hi"] - cell["mean"])
return lo, hi
def save(fig, stem):
OUTDIR.mkdir(parents=True, exist_ok=True)
for ext in ("pdf", "png"):
fig.savefig(OUTDIR / (stem + "." + ext), dpi=150, bbox_inches="tight")
plt.close(fig)
print("wrote", OUTDIR / (stem + ".pdf"))
def skip(name, why):
print("skip " + name + ": " + why)
def fig_baseline():
rtt_med = load_metric("rtt_median_ms__A"), load_metric("rtt_median_ms__B")
rtt_p95 = load_metric("rtt_p95_ms__A"), load_metric("rtt_p95_ms__B")
gp = load_metric("goodput_mbit__A"), load_metric("goodput_mbit__B")
cell = ("destination", "asym_latency", "")
if cell not in rtt_med[0] or cell not in gp[0]:
return skip("baseline", "cell " + str(cell) + " absent")
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8.0, 3.4))
labels = ["WAN-A", "WAN-B"]
colors = [C_A, C_B]
med = [rtt_med[i][cell]["median"] for i in (0, 1)]
err = [[max(0.0, rtt_med[i][cell]["median"] - rtt_med[i][cell]["ci95_lo"]) for i in (0, 1)],
[max(0.0, rtt_med[i][cell]["ci95_hi"] - rtt_med[i][cell]["median"]) for i in (0, 1)]]
ax1.bar(labels, med, color=colors, yerr=err, capsize=4, alpha=0.85)
for i in (0, 1):
if cell in rtt_p95[i]:
ax1.scatter([labels[i]], [rtt_p95[i][cell]["median"]], marker="_",
s=300, color="black", zorder=3,
label="p95" if i == 0 else None)
ax1.set_ylabel("Round-trip RTT [ms]")
ax1.set_title("(a) Per-link RTT (median, p95)")
ax1.legend(fontsize=8)
ax1.grid(True, axis="y", alpha=0.25)
g = [gp[i][cell]["mean"] for i in (0, 1)]
gerr = [[ci_err(gp[i][cell])[0] for i in (0, 1)],
[ci_err(gp[i][cell])[1] for i in (0, 1)]]
ax2.bar(labels, g, color=colors, yerr=gerr, capsize=4, alpha=0.85)
ax2.set_ylabel("TCP goodput [Mbit/s]")
ax2.set_title("(b) Per-link goodput")
ax2.grid(True, axis="y", alpha=0.25)
n = int(gp[0][cell]["n"])
fig.suptitle("Per-link baseline (destination, asym_latency, NAT, N=" + str(n) + ")",
fontsize=10)
fig.tight_layout()
save(fig, "fig_baseline")
def fig_cwnd_collapse():
gp = load_metric("goodput_mbit__svc_parallel")
runs = load_runs("goodput_mbit__svc_parallel")
pkt = ("ecmp_packet", "asym_latency", "")
flow = ("ecmp_flow", "asym_latency", "")
if pkt not in gp or flow not in gp:
return skip("cwnd_collapse", "cells absent")
fig, ax = plt.subplots(figsize=(5.2, 3.6))
labels = ["ECMP per-packet\n(spraying)", "ECMP per-flow\n(pinned)"]
cells = [pkt, flow]
colors = [C_FAIL, C_OK]
means = [gp[c]["mean"] for c in cells]
err = [[ci_err(gp[c])[0] for c in cells], [ci_err(gp[c])[1] for c in cells]]
ax.bar(labels, means, color=colors, yerr=err, capsize=4, alpha=0.85)
for i, c in enumerate(cells):
ax.scatter([i] * len(runs[c]), runs[c], color="black", s=12,
alpha=0.4, zorder=3)
ax.set_ylabel("Single-flow goodput [Mbit/s]")
ax.set_title("Single TCP flow, asym_latency (N=" + str(int(gp[pkt]["n"])) + ")")
ax.grid(True, axis="y", alpha=0.25)
fig.tight_layout()
save(fig, "fig_cwnd_collapse")
def fig_idle_vs_load():
series_rtt = load_metric("rtt_median_ms__svc_series")
cells = [k for k in series_rtt if k[0] == "ecmp_packet" and k[1] == "asym_jitter"]
idle = next((k for k in cells if k[2] == "idle"), None)
load = next((k for k in cells if k[2].startswith("load")), None)
if not idle or not load:
return skip("idle_vs_load", "idle/load cells absent")
panels = [
("rtt_median_ms__svc_series", "Series RTT median [ms]"),
("rtt_mdev_ms__svc_series", "Series RTT mdev (jitter) [ms]"),
("udp_loss_pct__udp_B", "UDP loss WAN-B [%]"),
("conntrack_count", "Conntrack entries"),
]
fig, axes = plt.subplots(1, 4, figsize=(12.5, 3.2))
xlabels = ["idle", load[2]]
for ax, (metric, ylabel) in zip(axes, panels):
m = load_metric(metric)
if idle not in m and load not in m:
ax.set_visible(False)
continue
vals, errs = [], [[], []]
for k in (idle, load):
if k in m:
vals.append(m[k]["mean"])
lo, hi = ci_err(m[k])
errs[0].append(lo)
errs[1].append(hi)
else:
vals.append(0.0)
errs[0].append(0.0)
errs[1].append(0.0)
ax.bar(xlabels, vals, color=[C_IDLE, C_LOAD], yerr=errs, capsize=4, alpha=0.85)
ax.set_ylabel(ylabel)
ax.grid(True, axis="y", alpha=0.25)
n = int(series_rtt[idle]["n"])
fig.suptitle("Idle vs. load (ecmp_packet, asym_jitter, N=" + str(n) +
"): pressure not saturation", fontsize=10)
fig.tight_layout()
save(fig, "fig_idle_vs_load")
def fig_session_continuity():
surv = load_metric("session_survived")
order = [
(("failover_metric", "asym_latency", "plain_idle"), "plain\nidle"),
(("failover_metric", "asym_latency", "plain_load200"), "plain\nload"),
(("failover_metric", "asym_latency", "plain_load120"), "plain\nload"),
(("failover_metric", "asym_latency", "nat_idle"), "nat\nidle"),
(("failover_metric", "asym_latency", "nat_load200"), "nat\nload"),
(("failover_metric", "asym_latency", "nat_load120"), "nat\nload"),
(("wireguard", "asym_latency", ""), "wg\n(nat)"),
]
present = [(k, lbl) for k, lbl in order if k in surv]
if not present:
return skip("session_continuity", "no session_survived cells")
fig, ax = plt.subplots(figsize=(6.4, 3.4))
labels = [lbl for _, lbl in present]
rates = [surv[k]["mean"] * 100 for k, _ in present]
colors = [C_OK if r >= 50 else C_FAIL for r in rates]
bars = ax.bar(labels, rates, color=colors, alpha=0.85)
for b, r, (k, _) in zip(bars, rates, present):
ax.text(b.get_x() + b.get_width() / 2, r + 2,
str(int(round(r))) + "%\n(n=" + str(int(surv[k]["n"])) + ")",
ha="center", fontsize=8)
ax.set_ylabel("TCP session survival [%]")
ax.set_ylim(0, 112)
ax.set_title("Session continuity across a routing failover")
ax.grid(True, axis="y", alpha=0.25)
fig.tight_layout()
save(fig, "fig_session_continuity")
def fig_detect_dist():
det = load_runs("detection_latency_s")
res = load_runs("restore_latency_s")
cell = ("failover_metric", "asym_latency", "")
if cell not in det:
return skip("detect_dist", "cell absent")
fig, ax = plt.subplots(figsize=(5.2, 3.6))
data = [det.get(cell, []), res.get(cell, [])]
bp = ax.boxplot(data, labels=["Detection", "Restore"], showmeans=True,
widths=0.5, patch_artist=True)
for patch, color in zip(bp["boxes"], (C_A, C_B)):
patch.set_facecolor(color)
patch.set_alpha(0.6)
for i, d in enumerate(data, start=1):
ax.scatter([i] * len(d), d, color="black", s=14, alpha=0.4, zorder=3)
ax.set_ylabel("Latency [s]")
ax.set_title("Health-check failover (interval 0.1 s, N=" + str(len(det[cell])) + ")")
ax.grid(True, axis="y", alpha=0.25)
fig.tight_layout()
save(fig, "fig_detect_dist")
def main():
if not SUMMARY.exists():
sys.exit("no summary dir: " + str(SUMMARY) + " (run aggregate.py first)")
print("reading " + str(SUMMARY) + ", writing " + str(OUTDIR))
fig_baseline()
fig_cwnd_collapse()
fig_idle_vs_load()
fig_session_continuity()
fig_detect_dist()
if __name__ == "__main__":
main()