-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_benchmarks.py
executable file
·105 lines (82 loc) · 2.81 KB
/
run_benchmarks.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
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
#! /usr/bin/env python
import docker
import os
import sys
IGNORE = ["client"]
def log(msg):
print(f"[run benchmarks] {msg}")
def get_langs():
os.chdir(sys.path[0])
return [
(lang, [
fname
for fname in os.listdir(lang)
if fname.startswith("Dockerfile")
])
for lang in os.listdir(".")
if os.path.isdir(lang)
if lang not in IGNORE
if any("Dockerfile" in fname for fname in os.listdir(lang))
if ".broken" not in os.listdir(lang)
]
def run_benchmark(d, lang, modes=["Dockerfile"]):
for mode in modes:
os.chdir(os.path.join(sys.path[0], lang))
mode_name = mode[len("Dockerfile"):]
bench_name = f"{lang}{mode_name}".lower()
log(f"Building docker image for benchmark {bench_name}")
image_name = f"server-benchmark-{lang.lower()}"
d.images.build(path=".", dockerfile=mode, tag=image_name)
log("Starting server application")
container = d.containers.run(
image_name,
auto_remove=True,
detach=True,
ports={8080: 8080}
)
log(f"Running benchmark {bench_name}")
os.chdir(os.path.join(sys.path[0], "client"))
exit_code = os.system("target/release/client benchmark")
if exit_code != 0:
log(f"Benchmark {bench_name} failed with exit code {exit_code}")
else:
log("Benchmark finished")
os.chdir(sys.path[0])
os.rename("client/bench.txt", f"results/{bench_name}.txt")
container.stop(timeout=1)
def setup_client():
os.chdir(os.path.join(sys.path[0], "client"))
log("Compiling benchmark client")
os.system("cargo build --release") # TODO: use docker
log("Generating test data")
os.system("target/release/client generate")
def main():
os.chdir(sys.path[0])
if not os.path.exists("results"):
os.mkdir("results")
d = docker.from_env()
if len(sys.argv) >= 2:
if (sys.argv[1] == "help"):
print("""Usage: ./run_benchmarks.py [<language> [mode]]
Examples: ./run_benchmarks.py Ruby yjit
./run_benchmarks.py Java
./run_benchmarks.py""")
return
lang = sys.argv[1]
setup_client()
if len(sys.argv) >= 3:
mode = sys.argv[2]
log(f"Benchmarking {lang} {mode}")
run_benchmark(d, lang, [f"Dockerfile-{mode}"])
else:
log(f"Benchmarking {lang}")
run_benchmark(d, lang, [f"Dockerfile"])
else:
langs = get_langs()
setup_client()
for (lang, modes) in langs:
log(f"Beginning benchmarking {lang}")
run_benchmark(d, lang, modes)
log("All benchmarks have finished")
if __name__ == "__main__":
main()