-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench-3-impls.py
executable file
·66 lines (50 loc) · 1.74 KB
/
bench-3-impls.py
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
#!/usr/bin/env python3
"""
Benchmark the /v1/city/get endpoint using various implementations.
Usage:
bench-closest.py [--runs=<n>]
Options:
--runs=<n> Number of runs to perform [default: 4].
"""
import os
from pathlib import Path
import subprocess
from docopt import docopt
IMAGE_BASE = 'gcr.io/strohel-goout-calendar/locations'
def main(runs):
tags = (
('actix-v30', {}),
('rocket-v04', {'ROCKET_WORKERS': '16', 'ROCKET_KEEP_ALIVE': '0'}),
('rocket-v05-dev', {}),
)
script_path = Path(__file__)
script_dir = script_path.parent.absolute()
test_image = str(script_dir / 'test-image.py')
render_tests = str(script_dir / 'render-tests.py')
for i in range(1, runs + 1):
for tag, env_overrides in tags:
outfile = f'{tag}-{i}.checks.bench.json'
if Path(outfile).exists():
print(f'{outfile} exists, skipping this benchmark.')
continue
env = {**os.environ, **env_overrides}
try:
run([test_image, f'{IMAGE_BASE}:{tag}', '--check-bad-env', '--log-threads', '--bench-out', outfile],
check=True, env=env)
except subprocess.CalledProcessError:
print('Called process exited with non-zero exit status, but continuing.')
run([render_tests])
# TODO: deduplicate
def run(program_args, **kwargs):
print(f"$ {' '.join(program_args)}")
try:
return subprocess.run(program_args, **kwargs)
except subprocess.CalledProcessError as e:
if e.stdout:
print(f"stdout: {e.stdout}")
if e.stderr:
print(f"stderr: {e.stderr}")
raise
if __name__ == '__main__':
args = docopt(__doc__)
main(int(args['--runs']))