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
"""Plot independently validated revision latency traces; paired trials are observations, not confidence intervals."""
from pathlib import Path
import sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from replay_latency import load_case
from replay_report import read_case
root = Path(sys.argv[1])
colors = ['#18765a', '#52677d', '#bf663e']
labels = ['Grouped ZKV', 'Legacy ZKV', 'RocksDB\nsync index']
rows = {name: load_case(root / name)[0] for name in
['grouped-1', 'grouped-2', 'legacy-1', 'legacy-2', 'rocks-1', 'rocks-2', 'poll-probe-1', 'poll-probe-2',
'notified-grouped-1', 'notified-grouped-2', 'notified-rocks-1', 'notified-rocks-2']}
plt.rcParams.update({'font.size': 11, 'svg.fonttype': 'none',
'axes.spines.top': False, 'axes.spines.right': False})
assert len({(row['frames'], row['corpus_sha256'], row['rate'], row['workers'], row['db_pool'], row['db_cpus']) for row in rows.values()}) == 1
fig, axes = plt.subplots(4, 1, figsize=(7, 11.5), layout='constrained')
for ax, quantile, title in [(axes[0], 'p50_ms', 'Median ingress-to-receipt latency'),
(axes[1], 'p99_ms', 'p99 ingress-to-receipt latency')]:
for y, (engine, color) in enumerate(zip(['grouped', 'legacy', 'rocks'], colors)):
values = [rows[f'{engine}-{trial}']['latencies']['from_ingress'][quantile] for trial in [1, 2]]
ax.plot(values, [y, y], color=color, linewidth=2, alpha=.5)
for value, marker in zip(values, ['o', 'x']):
ax.scatter(value, y, color=color, marker=marker, s=55, zorder=3)
ax.set(yticks=range(3), yticklabels=labels, xlabel='Milliseconds', title=title, ylim=(-.5, 2.5), xlim=(0, None))
ax.grid(axis='x', alpha=.16)
axes[0].scatter([], [], marker='o', color='#333333', label='Trial 1')
axes[0].scatter([], [], marker='x', color='#333333', label='Trial 2')
axes[0].legend(frameon=False, loc='upper left', ncols=2, fontsize=9)
for y, (prefix, label, color) in enumerate([('grouped', 'Original 100 ms idle poll', '#52677d'),
('poll-probe', 'Throwaway 1 ms idle poll', '#18765a')]):
values = [rows[f'{prefix}-{trial}']['latencies']['from_ingress']['p50_ms'] for trial in [1, 2]]
axes[2].plot(values, [y, y], color=color, linewidth=2, alpha=.5)
for value, marker, offset in zip(values, ['o', 'x'], [9, -17]):
axes[2].scatter(value, y, color=color, marker=marker, s=55, zorder=3)
axes[2].annotate(f'{value:.1f}', (value, y), xytext=(0, offset), textcoords='offset points', ha='center', fontsize=9)
axes[2].set(yticks=[0, 1], yticklabels=['Original\n100 ms poll', 'Probe\n1 ms poll'],
xlabel='Median milliseconds · grouped ZKV unchanged',
title='Shared consumer polling affects the median', ylim=(-.5, 1.5), xlim=(0, 80))
axes[2].grid(axis='x', alpha=.16)
cpu_cases = [('grouped', 'Grouped\nbaseline', '#52677d'),
('notified-grouped', 'Grouped\nnotified', '#18765a'),
('rocks', 'RocksDB\nbaseline', '#52677d'),
('notified-rocks', 'RocksDB\nnotified', '#bf663e')]
for y, (prefix, label, color) in enumerate(cpu_cases):
values = [read_case(root / f'{prefix}-{trial}')['resources']['relay']['cpu_s'] for trial in [1, 2]]
axes[3].plot(values, [y, y], color=color, linewidth=2, alpha=.5)
for value, marker in zip(values, ['o', 'x']):
axes[3].scatter(value, y, color=color, marker=marker, s=55, zorder=3)
axes[3].set(yticks=range(4), yticklabels=[case[1] for case in cpu_cases],
xlabel='Relay CPU seconds · ingestion plus oracle readback',
title='Notification prototype has a measured CPU cost', xlim=(0, 6.2))
axes[3].grid(axis='x', alpha=.16)
fig.suptitle('Offline relay receipt latency\nSame 8,016 signed frames at 600/s; two sequential trials per variant', fontsize=13)
fig.savefig(root / 'comparison.svg', facecolor='white')
fig.savefig(root / 'comparison.png', facecolor='white', dpi=140)
svg = root / 'comparison.svg'
svg.write_text('\n'.join(line.rstrip() for line in svg.read_text().splitlines()) + '\n')