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
"""Run a bounded, network-free load suite in an isolated disposable Fly app."""
import argparse
import csv
import json
import hashlib
import signal
import subprocess
import time
import uuid
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('zkv_binary', type=Path)
parser.add_argument('rocks_binary', type=Path)
parser.add_argument('output', type=Path)
parser.add_argument('--confirm', action='store_true')
parser.add_argument('--pilot', action='store_true')
parser.add_argument('--qualify', action='store_true')
parser.add_argument('--maintenance-policy', action='store_true')
parser.add_argument('--allocator-check', action='store_true')
parser.add_argument('--runtime-binary', type=Path)
parser.add_argument('--diagnostic', action='store_true')
parser.add_argument('--recovery-binary', type=Path)
parser.add_argument('--grouped-recovery-only', action='store_true')
args = parser.parse_args()
for binary in [args.zkv_binary, args.rocks_binary]:
if not binary.is_file() or binary.stat().st_size > 20_000_000:
raise ValueError('provide existing stripped load binaries below 20 MB')
args.output.mkdir(parents=True, exist_ok=True)
app = 'zkv-zlay-audit-' + uuid.uuid4().hex[:10]
state = {'app': app, 'region': 'ord', 'created': False, 'cleanup_verified': False}
state['binaries'] = {}
for name, binary in [('zkv', args.zkv_binary), ('rocks', args.rocks_binary), ('runtime', args.runtime_binary), ('recovery', args.recovery_binary)]:
if binary:
state['binaries'][name] = {'bytes': binary.stat().st_size, 'sha256': hashlib.sha256(binary.read_bytes()).hexdigest()}
repo = Path(__file__).resolve().parents[2]
state['compiler'] = subprocess.check_output(['zig', 'version'], text=True).strip()
core = repo.parent.parent / 'zzstoatzz.io/zkv'
state['core'] = {'revision': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=core, text=True).strip(), 'files': {str(p.relative_to(core)): hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted((core / 'src').rglob('*.zig'))}}
state['source'] = {}
for name, source in [('zkv', repo), ('rocks', repo.parent / 'zlay-zkv-pilot')]:
state['source'][name] = {
'revision': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=source, text=True).strip(),
'files': {str(file): hashlib.sha256((source / file).read_bytes()).hexdigest() for file in
[Path('build.zig'), Path('build.zig.zon'), *sorted(p.relative_to(source) for p in (source / 'src').rglob('*.zig'))]},
}
state_path = args.output / 'fly-resources.json'
def save():
state_path.write_text(json.dumps(state, indent=2) + '\n')
def run(command, **kwargs):
return subprocess.run(command, check=True, text=True, **kwargs)
def terminate(signum, frame):
raise KeyboardInterrupt(f'signal {signum}')
signal.signal(signal.SIGTERM, terminate)
save()
created = False
try:
run(['fly', 'apps', 'create', app, '--org', 'personal', '--yes'])
created = True
state['created'] = True
save()
volume = run(['fly', 'volumes', 'create', 'audit_data', '-a', app, '-r', 'ord',
'--size', '1', '--scheduled-snapshots=false', '--yes', '--json'], capture_output=True)
state['volume'] = json.loads(volume.stdout)
save()
run(['fly', 'machine', 'run', 'debian:bookworm-slim', 'sleep', '1800',
'-a', app, '-r', 'ord', '--name', 'load-test', '--vm-cpu-kind', 'performance',
'--vm-cpus', '2', '--vm-memory', '4096', '--volume', 'audit_data:/data',
'--restart', 'no', '--rm', '--detach'], timeout=180)
machines = run(['fly', 'machine', 'list', '-a', app, '--json'], capture_output=True)
state['machines'] = json.loads(machines.stdout)
save()
uploads = [('zkv', args.zkv_binary)]
if not args.diagnostic:
uploads.append(('rocks', args.rocks_binary))
for name, binary in uploads:
run(['fly', 'ssh', 'sftp', 'put', '-a', app, '--mode', '0755', str(binary.resolve()), '/data/' + name], timeout=120)
cases = []
if args.allocator_check:
order = [('rocks-sync-c', 'rocks', 'sync', 1), ('rocks-sync-process', 'rocks', 'sync', 1), ('zkv-c', 'zkv', 'default', 16), ('zkv-process', 'zkv', 'default', 16)]
for engine, binary, mode, batch in order + list(reversed(order)):
cases.append((engine, binary, mode, 5000, 10, batch, 30, 1_000_000))
elif args.grouped_recovery_only:
if not args.recovery_binary:
raise ValueError('grouped recovery requires recovery binary')
elif args.maintenance_policy:
for order in [256, 4096, 4096, 256]:
cases.append((f'zkv-segments-{order}', 'zkv', 'default', 5000, 10, 16, 60, 1_000_000))
elif args.qualify:
cases = [('rocks-default', 'rocks', 'default', 5000, 10, 1, 30, 1_000_000),
('rocks-sync', 'rocks', 'sync', 5000, 10, 1, 30, 1_000_000),
('zkv-nowait', 'zkv', 'default', 5000, 10, 16, 30, 1_000_000),
('zkv-window', 'zkv', 'default', 5000, 10, 16, 30, 1_000_000)]
elif args.pilot:
cases = [('rocks-default', 'rocks', 'default', 1000, 10, 1, 5, 65536),
('rocks-sync', 'rocks', 'sync', 1000, 10, 1, 5, 65536),
('zkv-pilot', 'zkv', 'default', 1000, 10, 16, 5, 65536)]
elif args.diagnostic:
for trial in range(3):
order = ['zkv-maintenance', 'zkv-deferred'] if trial % 2 == 0 else ['zkv-deferred', 'zkv-maintenance']
for engine in order:
cases.append((engine, 'zkv', 'default', 5000, 10, 64, 15, 1_000_000))
elif args.confirm:
for batch in [8, 64]:
for engine, binary, mode in [('rocks-default', 'rocks', 'default'), ('rocks-sync', 'rocks', 'sync'), ('zkv', 'zkv', 'default')]:
cases.append((engine, binary, mode, 5000, 10, batch, 15, 1_000_000))
for rate, novelty, batch in [(5000, 10, 8), (5000, 10, 64), (20000, 10, 64), (5000, 0, 64), (5000, 100, 64)]:
cases.append(('zkv', 'zkv', 'default', rate, novelty, batch, 30, 1_000_000))
else:
for rate in [1000, 5000, 20000]:
for novelty in [10, 100]:
for batch in [1, 8, 64]:
engines = [('rocks-default', 'rocks', 'default'), ('rocks-sync', 'rocks', 'sync'), ('zkv', 'zkv', 'default')]
rotation = len(cases) // 3 % 3
for engine, binary, mode in engines[rotation:] + engines[:rotation]:
cases.append((engine, binary, mode, rate, novelty, batch, 5, 4096))
shell = ['#!/bin/sh', 'set -eu', 'uname -a > /data/environment.txt',
'cat /proc/cpuinfo >> /data/environment.txt', 'df -T /data >> /data/environment.txt',
'ldd /data/rocks >> /data/environment.txt 2>&1 || true',
': > /data/results.csv', ': > /data/progress.txt']
if args.runtime_binary:
run(['fly', 'ssh', 'sftp', 'put', '-a', app, '--mode', '0755',
str(args.runtime_binary.resolve()), '/data/runtime'], timeout=120)
shell += [': > /data/runtime.csv']
for trial in range(3):
shell += [f'timeout -k 5 15 /data/runtime /data/runtime-{trial} > /data/runtime-one.csv 2>> /data/bench.log']
if trial == 0:
shell += ['head -1 /data/runtime-one.csv | sed "s/^/trial,/" >> /data/runtime.csv']
shell += [f'tail -n +2 /data/runtime-one.csv | sed "s/^/{trial},/" >> /data/runtime.csv']
queue_limit = 64 if args.pilot or args.qualify or args.maintenance_policy or args.allocator_check else 16
for number, (engine, binary, mode, rate, novelty, batch, seconds, seeds) in enumerate(cases):
extra = ' defer-maintenance' if engine == 'zkv-deferred' else ''
if args.allocator_check:
extra = ' 4 0 --allocator=' + engine.rsplit('-', 1)[1]
elif args.maintenance_policy:
extra = ' 4 0 ' + engine.rsplit('-', 1)[1]
elif args.qualify:
extra = ' 4 ' + ('1000' if engine == 'zkv-window' else '0')
shell += [f'echo "case {number} {engine} {rate} {novelty} {batch}" >> /data/progress.txt',
f'echo "case,{number},{engine}" >> /data/bench.log',
'rm -rf /data/bench-current',
f'timeout -k 5 240 /data/{binary} /data/bench-current {rate} {seconds} {batch} {novelty} 100 {mode} {queue_limit} {seeds}{extra} > /data/one.csv 2>> /data/bench.log',
f'cp /data/one.csv /data/result-{number}.csv',
f'tail -1 /data/one.csv | sed "s/^/{number},{engine},/" >> /data/results.csv']
if number == 0:
shell.insert(len(shell) - 1, 'head -1 /data/one.csv | sed "s/^/case,engine,/" >> /data/results.csv')
shell += ['rm -rf /data/bench-current']
exports = ['results.csv', 'environment.txt', 'progress.txt', 'bench.log'] + [f'result-{number}.csv' for number in range(len(cases))]
if args.runtime_binary:
exports.append('runtime.csv')
if args.recovery_binary:
run(['fly', 'ssh', 'sftp', 'put', '-a', app, '--mode', '0755',
str(args.recovery_binary.resolve()), '/data/recovery'], timeout=120)
shell += [': > /data/recovery.csv']
exports.append('recovery.csv')
write_mode = 'group-write' if args.grouped_recovery_only else 'write'
verify_mode = 'group-verify' if args.grouped_recovery_only else 'verify'
for batch in [1, 8, 64]:
for delay in [0.1, 1, 3]:
shell += ['rm -rf /data/crash-current',
f'/data/recovery /data/crash-current {write_mode} {batch} 0 > /data/acks 2>> /data/bench.log &',
'pid=$!', f'sleep {delay}', 'kill -9 "$pid"', 'wait "$pid" || true',
"ack=$(tail -2 /data/acks | head -1)",
'test -n "$ack"',
f'/data/recovery /data/crash-current {verify_mode} {batch} "$ack" >> /data/recovery.csv 2>> /data/bench.log']
shell += ['rm -rf /data/crash-current']
shell += ['echo complete >> /data/progress.txt']
suite = args.output / 'suite.sh'
suite.write_text('\n'.join(shell) + '\n')
run(['fly', 'ssh', 'sftp', 'put', '-a', app, str(suite.resolve()), '/data/suite.sh'], timeout=120)
run(['fly', 'ssh', 'console', '-a', app, '-C', 'sh /data/suite.sh'], timeout=1200)
for name in exports:
run(['fly', 'ssh', 'sftp', 'get', '-a', app, '/data/' + name, str((args.output / name).resolve())], timeout=120)
if cases:
rows = []
fields = ['case', 'engine']
for number, case in enumerate(cases):
path = args.output / f'result-{number}.csv'
with path.open(newline='') as source:
reader = csv.DictReader(source)
observed = list(reader)
if len(observed) != 1 or None in observed[0] or any(v is None for v in observed[0].values()):
raise ValueError(f'invalid result schema: {path}')
for field in reader.fieldnames:
if field not in fields:
fields.append(field)
rows.append({'case': number, 'engine': case[0], **observed[0]})
with (args.output / 'results.csv').open('w', newline='') as output:
writer = csv.DictWriter(output, fieldnames=fields)
writer.writeheader()
writer.writerows(rows)
state['results_schema'] = 'union of per-case headers; unavailable fields empty'
state['suite_complete'] = True
save()
finally:
if created:
# Export partial evidence before deleting a failed run as well.
if not state.get('suite_complete'):
for name in ['results.csv', 'progress.txt', 'bench.log']:
try:
subprocess.run(['fly', 'ssh', 'sftp', 'get', '-a', app, '/data/' + name,
str((args.output / ('partial-' + name)).resolve())], timeout=30)
except (subprocess.TimeoutExpired, OSError) as error:
state.setdefault('export_errors', []).append({'file': name, 'error': type(error).__name__})
for attempt in range(3):
try:
cleanup = subprocess.run(['fly', 'apps', 'destroy', app, '--yes'], timeout=120)
except (subprocess.TimeoutExpired, OSError) as error:
state.setdefault('cleanup_errors', []).append(type(error).__name__)
save()
continue
if cleanup.returncode == 0:
break
time.sleep(2)
apps = run(['fly', 'apps', 'list', '--json'], capture_output=True)
remaining = json.loads(apps.stdout)
state['cleanup_verified'] = not any(x.get('Name', x.get('name')) == app for x in remaining)
save()
if not state['cleanup_verified']:
raise RuntimeError('disposable app cleanup could not be verified: ' + app)