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
import argparse
import json
import re
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument('root', type=Path)
parser.add_argument('output', type=Path)
args = parser.parse_args()
fig, axes = plt.subplots(1, 3, figsize=(13, 5.2))
for name, label, color in [('one-gib', '1 GiB VM · OOM', '#b55b25'), ('two-gib', '2 GiB VM · completed', '#176d9c')]:
root = args.root / name
samples = [json.loads(line) for line in (root / 'samples.jsonl').read_text().splitlines()]
summary = json.loads((root / 'summary.json').read_text())
axes[0].plot([s['seconds'] for s in samples], [s['messages'] for s in samples], color=color, label=label, linewidth=2)
rss = [(s['seconds'], int(m.group(1)) / 1024) for s in samples
if (m := re.search(r'^VmRSS:\s+(\d+)', s['status'] or '', re.M))]
axes[1].plot(*zip(*rss), color=color, linewidth=2)
queue = [(s['seconds'], float(m.group(1)) / 2**20) for s in samples
if (m := re.search(r'^relay_pool_queued_bytes\s+(\S+)', s['metrics'] or '', re.M))]
axes[2].plot(*zip(*queue), color=color, linewidth=2)
if summary['stopped'] == 'relay-exited':
axes[0].annotate('Relay OOM-killed', xy=(summary['seconds'], summary['messages']), xytext=(20, 4500),
fontsize=9, arrowprops={'arrowstyle': '->', 'color': color}, color=color)
for ax, title, unit in zip(axes, ['Downstream delivery', 'Relay resident memory', 'Queued frame data'], ['Events received by subscriber', 'MiB RSS', 'MiB queued']):
ax.set_title(title, loc='left', fontsize=12)
ax.set_xlabel('Seconds from observation start')
ax.set_ylabel(unit)
ax.set_xlim(0, 46)
ax.set_ylim(bottom=0)
ax.spines[['top','right']].set_visible(False)
ax.grid(alpha=.16)
axes[0].legend(frameon=False, fontsize=8, loc='upper left')
fig.suptitle('Live ZKV relay with replay history disabled', x=.07, ha='left', fontsize=17)
fig.text(.07,.88,'Full host discovery, real upstream sockets and a downstream subscriber; 2 shared CPUs; PostgreSQL on the same VM.',fontsize=10)
fig.text(.07,.045,'Separate live windows with different arrivals. Not a matched throughput comparison. Metrics stopped responding before the 1 GiB OOM.',fontsize=9)
fig.subplots_adjust(left=.07,right=.98,top=.76,bottom=.21,wspace=.42)
fig.savefig(args.output,facecolor='white')
if args.output.suffix == '.svg':
args.output.write_text('\n'.join(line.rstrip() for line in args.output.read_text().splitlines()) + '\n')
fig.savefig(args.output.with_suffix('.png'),dpi=150,facecolor='white')