-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.py
executable file
·376 lines (330 loc) · 10.6 KB
/
run.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env python3
import os
import sys
import time
import shutil
import signal
import pexpect
import pathlib
import argparse
import termcolor
"""
Below are listed the supported databases, benchmark sizes, workloads and more settings.
All of them are optional and treated as defaults, so you can select settings here or pass arguments from outside.
Usage: sudo ./run.py [arguments], type -h or --help for help.
Note there are some databases and sizes commented by default just to minimize the sample run, so select them according to your needs.
"""
db_names = [
"ustore",
"rocksdb",
"leveldb",
"wiredtiger",
# "mongodb",
# "redis",
# "lmdb",
]
sizes = [
"100MB",
# "1GB",
# "10GB",
# "100GB",
# "1TB",
# "10TB",
]
workload_names = [
"Init",
"Read",
"BatchRead",
"RangeSelect",
"Scan",
"ReadUpdate_50_50",
"ReadUpsert_95_5",
"BatchUpsert",
"Remove",
]
threads_count = 1
transactional = False
drop_caches = False
run_in_docker_container = False
main_dir_path = "./db_main/"
storage_disk_paths = [
# '/disk1/db_storage/',
# '/disk2/db_storage/',
]
def get_db_config_file_path(db_name: str, size: str) -> str:
path = os.path.join("./bench/configs", db_name, f"{size}.cfg")
if not pathlib.Path(path).exists():
path = os.path.join("./bench/configs", db_name, "default.cfg")
return path
def get_workloads_file_path(size: str) -> str:
return os.path.join("./bench/workloads", f"{size}.json")
def get_db_main_dir_path(db_name: str, size: str, main_dir_path: str) -> str:
return os.path.join(main_dir_path, db_name, size, "")
def get_db_storage_dir_paths(db_name: str, size: str, storage_disk_paths: str) -> list:
db_storage_dir_paths = []
for storage_disk_path in storage_disk_paths:
db_storage_dir_paths.append(os.path.join(storage_disk_path, db_name, size, ""))
return db_storage_dir_paths
def get_results_file_path(
db_name: str,
size: str,
drop_caches: bool,
transactional: bool,
storage_disk_paths: str,
threads_count: int,
) -> str:
root_dir_path = ""
if drop_caches:
if transactional:
root_dir_path = "./bench/results/without_caches/transactional/"
else:
root_dir_path = "./bench/results/without_caches/"
else:
if transactional:
root_dir_path = "./bench/results/transactional/"
else:
root_dir_path = "./bench/results/"
disks_count = max(len(storage_disk_paths), 1)
return os.path.join(
f"{root_dir_path}cores_{threads_count}",
f"disks_{disks_count}",
db_name,
f"{size}.json",
)
def drop_system_caches():
print(end="\x1b[1K\r")
print(" [✱] Dropping system caches...", end="\r")
try:
with open("/proc/sys/vm/drop_caches", "w") as stream:
stream.write("3\n")
time.sleep(8) # Wait for other apps to reload its caches
except KeyboardInterrupt:
print(termcolor.colored("Terminated by user", "yellow"))
exit(1)
except:
print(termcolor.colored("Failed to drop system caches", "red"))
exit(1)
def run(
db_name: str,
size: str,
workload_names: list,
main_dir_path: str,
storage_disk_paths: str,
transactional: bool,
drop_caches: bool,
run_in_docker_container: bool,
threads_count: bool,
run_index: int,
runs_count: int,
) -> None:
db_config_file_path = get_db_config_file_path(db_name, size)
workloads_file_path = get_workloads_file_path(size)
db_main_dir_path = get_db_main_dir_path(db_name, size, main_dir_path)
db_storage_dir_paths = get_db_storage_dir_paths(db_name, size, storage_disk_paths)
results_file_path = get_results_file_path(
db_name, size, drop_caches, transactional, storage_disk_paths, threads_count
)
transactional_flag = "-t" if transactional else ""
filter = ",".join(workload_names)
db_storage_dir_paths = ",".join(db_storage_dir_paths)
runner: str
if run_in_docker_container:
runner = f"docker run -v {os.getcwd()}/bench:/ucsb/bench -v {os.getcwd()}/tmp:/ucsb/tmp -it ucsb-image-dev"
else:
runner = "./build_release/build/bin/ucsb_bench"
if not os.path.exists(runner):
raise Exception("First, please build the runner: `build_release.sh`")
process = pexpect.spawn(
f'{runner} -db {db_name} {transactional_flag} -cfg "{db_config_file_path}" -wl "{workloads_file_path}" -md "{db_main_dir_path}" -sd "{db_storage_dir_paths}" -res "{results_file_path}" -th {threads_count} -fl {filter} -ri {run_index} -rc {runs_count}'
)
process.interact()
process.close()
# Handle signal
if process.signalstatus:
sig = signal.Signals(process.signalstatus)
if sig == signal.SIGINT:
print(termcolor.colored("Benchmark terminated by user", "yellow"))
else:
print(
termcolor.colored(f"Benchmark terminated (signal: {sig.name})", "red")
)
exit(process.signalstatus)
def parse_args():
global db_names
global sizes
global workload_names
global main_dir_path
global storage_disk_paths
global threads_count
global transactional
global drop_caches
global run_in_docker_container
parser = argparse.ArgumentParser()
parser.add_argument(
"-db",
"--db-names",
help="Database name(s)",
nargs="+",
required=False,
default=db_names,
)
parser.add_argument(
"-sz",
"--sizes",
help="Benchmark size(s)",
nargs="+",
required=False,
default=sizes,
)
parser.add_argument(
"-wl",
"--workload-names",
help="Workload name(s)",
nargs="+",
required=False,
default=workload_names,
)
parser.add_argument(
"-md",
"--main-dir",
help="Main directory",
type=str,
required=False,
default=main_dir_path,
)
parser.add_argument(
"-sd",
"--storage-dirs",
help="Storage directories",
nargs="+",
required=False,
default=storage_disk_paths,
)
parser.add_argument(
"-th",
"--threads",
help="Threads count",
type=int,
required=False,
default=threads_count,
)
parser.add_argument(
"-tx",
"--transactional",
help="Transactional benchmark",
action=argparse.BooleanOptionalAction,
default=transactional,
)
parser.add_argument(
"-dp",
"--drop-caches",
help="Drops system cashes before each benchmark",
action=argparse.BooleanOptionalAction,
default=drop_caches,
)
parser.add_argument(
"-rd",
"--run-docker",
help="Runs the benchmark in a docker container",
action=argparse.BooleanOptionalAction,
default=run_in_docker_container,
)
args = parser.parse_args()
db_names = args.db_names
sizes = args.sizes
workload_names = args.workload_names
main_dir_path = args.main_dir
storage_disk_paths = args.storage_dirs
threads_count = args.threads
transactional = args.transactional
drop_caches = args.drop_caches
run_in_docker_container = args.run_docker
def check_args():
global db_names
global sizes
global workload_names
if not db_names:
sys.exit("Database(s) not specified")
if not sizes:
sys.exit("Database size(s) not specified")
if not workload_names:
sys.exit("Workload name(s) not specified")
def main() -> None:
if os.geteuid() != 0:
print(termcolor.colored(f"Run as sudo!", "red"))
sys.exit(-1)
parse_args()
check_args()
# Cleanup old DBs (Note: It actually cleanups if the first workload is `Init`)
if workload_names[0] == "Init":
print(end="\x1b[1K\r")
print(" [✱] Cleanup...", end="\r")
for size in sizes:
for db_name in db_names:
# Remove DB main directory
db_main_dir_path = get_db_main_dir_path(db_name, size, main_dir_path)
if pathlib.Path(db_main_dir_path).exists():
shutil.rmtree(db_main_dir_path)
# Remove DB storage directories
db_storage_dir_paths = get_db_storage_dir_paths(
db_name, size, storage_disk_paths
)
for db_storage_dir_path in db_storage_dir_paths:
if pathlib.Path(db_storage_dir_path).exists():
shutil.rmtree(db_storage_dir_path)
# Run benchmarks
for size in sizes:
for db_name in db_names:
# Create DB main directory
db_main_dir_path = get_db_main_dir_path(db_name, size, main_dir_path)
pathlib.Path(db_main_dir_path).mkdir(parents=True, exist_ok=True)
# Create DB storage directories
db_storage_dir_paths = get_db_storage_dir_paths(
db_name, size, storage_disk_paths
)
for db_storage_dir_path in db_storage_dir_paths:
pathlib.Path(db_storage_dir_path).mkdir(parents=True, exist_ok=True)
# Create results dir paths
results_file_path = get_results_file_path(
db_name,
size,
drop_caches,
transactional,
storage_disk_paths,
threads_count,
)
pathlib.Path(results_file_path).parent.mkdir(parents=True, exist_ok=True)
# Run benchmark
if drop_caches:
for i, workload_name in enumerate(workload_names):
if not run_in_docker_container:
drop_system_caches()
run(
db_name,
size,
[workload_name],
main_dir_path,
storage_disk_paths,
transactional,
drop_caches,
run_in_docker_container,
threads_count,
i,
len(workload_names),
)
else:
run(
db_name,
size,
workload_names,
main_dir_path,
storage_disk_paths,
transactional,
drop_caches,
run_in_docker_container,
threads_count,
0,
1,
)
if __name__ == "__main__":
main()