forked from NVIDIA/spark-rapids-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nds_bench.py
506 lines (451 loc) · 20.4 KB
/
nds_bench.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----
#
# Certain portions of the contents of this file are derived from TPC-DS version 3.2.0
# (retrieved from www.tpc.org/tpc_documents_current_versions/current_specifications5.asp).
# Such portions are subject to copyrights held by Transaction Processing Performance Council (“TPC”)
# and licensed under the TPC EULA (a copy of which accompanies this file as “TPC EULA” and is also
# available at http://www.tpc.org/tpc_documents_current_versions/current_specifications5.asp) (the “TPC EULA”).
#
# You may not use this file except in compliance with the TPC EULA.
# DISCLAIMER: Portions of this file is derived from the TPC-DS Benchmark and as such any results
# obtained using this file are not comparable to published TPC-DS Benchmark results, as the results
# obtained from using this file do not comply with the TPC-DS Benchmark.
#
#
# 1. run nds_transcode.py to load data to Iceberg or DeltaLake. => get "TLoad" and "timestamp" for 2.
# 2. run nds_gen_query_stream.py to generate query streams with RNDSEED = "timestamp" from 1.
# TPC-DS specification requires Sq >= 4, but this script allow Sq >= 1 for test purpose.
# 3. run nds_power.py to do Power Test => get "TPower"
# 4. run nds-throughput to do Throughput Test 1. => get "Ttt1"
# 5. run nds_maintenance.py to do Maintenance Test 1. => get "Tdm1"
# 6. run nds-throughput to do Throughput Test 2. => get "Ttt2"
# 7. run nds_maintenance.py to do Maintenance Test 2. => get "Tdm2"
import argparse
import math
import subprocess
import yaml
def get_yaml_params(yaml_file):
with open(yaml_file, 'r') as f:
try:
params = yaml.safe_load(f)
return params
except yaml.YAMLError as exc:
print(exc)
return None
def get_load_end_timestamp(load_report_file):
"""get the end timestamp in str format from the load report file.
this timestamp will be used to generate query streams as the RNDSEED input argument.
"""
rngseed = None
with open(load_report_file, "r") as f:
for line in f:
if "RNGSEED used:" in line:
# e.g. "RNGSEED used: 07291122510"
rngseed = line.split(":")[1].strip()
if not rngseed:
raise Exception(
f"RNGSEED not found in Load Test report file: {load_report_file}")
else:
return rngseed
def get_load_time(load_report_file):
"""get the load test elapse time in str format from the load report file"""
load_elapse = None
with open(load_report_file, "r") as f:
for line in f:
if "Load Test Time" in line:
# e.g. "Load Test Time: 1234 seconds"
load_elapse = line.split(":")[1].split(" ")[1]
if load_elapse:
return load_elapse
else:
raise Exception(
f"Load Test Time not found in Load Test report file: {load_report_file}.")
def get_power_time(power_report_file):
"""get the total elapse time for Power Test in str format from the power report file"""
power_elapse = None
with open(power_report_file, "r") as f:
for line in f:
if "Power Test Time" in line:
# e.g. "app-20220715143743-0007,Power Test Time,11838"
power_elapse = line.split(",")[2].strip()
if power_elapse:
return power_elapse
else:
raise Exception(
f"Power Test Time not found in Power Test report file: {power_report_file}.")
def get_start_end_time(report_file):
"""get the start timestamp in str format from the Power Test report file"""
start_time = None
end_time = None
with open(report_file, "r") as f:
for line in f:
if "Power Start Time" in line:
# e.g. "app-20220715143743-0007,Power Start Time,1659067405.468058"
start_time = line.split(",")[2].strip()
if "Power End Time" in line:
# e.g. "app-20220715143743-0007,Power End Time,1659067405.468058"
end_time = line.split(",")[2].strip()
if start_time and end_time:
return start_time, end_time
else:
raise Exception(
f"Start or End time not found in Power Test report file: {report_file}")
def get_stream_range(num_streams, first_or_second):
"""get the range of stream numbers for the given number of total streams and the index of throughput test
e.g. num_streams = 9, first_or_second = 1 => return [1,2,3,4]
e.g. num_streams = 9, first_or_second = 2 => return [5,6,7,8]
"""
if first_or_second == 1:
stream_range = [x for x in range(1, num_streams//2+1)]
else:
stream_range = [x for x in range(num_streams//2+1, num_streams)]
return stream_range
def get_throughput_time(throughput_report_file_base, num_streams, first_or_second):
"""get Throughput elapse time according to Spec 7.4.7.4.
Filter all Throughput reports and get the start timestamp and end timestamp to calculate the
elapse time of Throughput Test
num_streams (int): number of streams in total including Power Stream
first_or_second (int): 1 for first throughput test, 2 for second throughput test
"""
start_time = []
end_time = []
stream_range = get_stream_range(num_streams, first_or_second)
for stream_num in stream_range:
report_file = throughput_report_file_base + f"_{stream_num}.csv"
sub_start_time, sub_end_time = get_start_end_time(report_file)
start_time.append(float(sub_start_time))
end_time.append(float(sub_end_time))
start_time = min(start_time)
end_time = max(end_time)
elapse = round_up_to_nearest_10_percent(end_time - start_time)
return elapse
def get_refresh_time(maintenance_report_file):
"""get Maintenance elapse time from report"""
maintenance_elapse = None
with open(maintenance_report_file, "r") as f:
for line in f:
if "Data Maintenance Time" in line:
# e.g. "app-20220715143743-0007,Data Maintenance Time,11838"
maintenance_elapse = line.split(",")[2].strip()
if maintenance_elapse:
return float(maintenance_elapse)
else:
raise Exception("Data Maintenance Time not found in Data Maintenance report file: " +
f"{maintenance_report_file}.")
def get_maintenance_time(maintenance_report_base_path,
num_streams, first_or_second):
"""Get maintenance time from maintenance report files generated in one maintenance test.
THe maintenance time is the sum of the elapse time of all maintenance reports in one maintenance test.
Args:
maintenance_report_base_path (str): base path of maintenance report files.
num_streams (int): total number of streams.
first_or_second (int): 1 or 2 for first or second maintenance test.
Returns:
float: elapse time of maintenance test.
"""
refresh_nums = get_stream_range(num_streams, first_or_second)
Tdm = 0
# refresh run for each stream in Throughput Test 1.
for i in refresh_nums:
maintenance_report_path = maintenance_report_base_path + \
f"_{i}" + ".csv"
Tdm += float(get_refresh_time(maintenance_report_path))
return round_up_to_nearest_10_percent(Tdm)
def get_throughput_stream_nums(num_streams, first_or_second):
"""only used for throughput run script, get the stream numbers for throughput test in a comma
separated string. e.g. "1,2,3,4" for num_streams = 9, first_or_second = 1
"""
int_range = get_stream_range(num_streams, first_or_second)
return ",".join([str(x) for x in int_range])
def round_up_to_nearest_10_percent(num):
return math.ceil(num * 10) / 10
def run_data_gen(scale_factor, parallel, data_path, local_or_hdfs, num_streams):
gen_data_cmd = ["python3",
"nds_gen_data.py",
local_or_hdfs,
scale_factor,
parallel,
data_path,
"--overwrite_output"]
subprocess.run(gen_data_cmd, check=True)
for i in range(1, num_streams):
gen_refresh_data_cmd = ["python3",
"nds_gen_data.py",
local_or_hdfs,
scale_factor,
parallel,
data_path + f"_{i}",
"--overwrite_output",
"--update", str(i)]
subprocess.run(gen_refresh_data_cmd, check=True)
def run_load_test(template_path,
input_path,
output_path,
warehouse_type,
load_report_file):
load_test_cmd = ["./spark-submit-template",
template_path,
"nds_transcode.py",
input_path,
output_path,
load_report_file,
"--output_format", warehouse_type,
"--output_mode", "overwrite",
"--log_level", "WARN"]
subprocess.run(load_test_cmd, check=True)
def gen_streams(num_streams,
template_dir,
scale_factor,
stream_output_path,
RNGSEED):
gen_stream_cmd = ["python3",
"nds_gen_query_stream.py",
template_dir,
scale_factor,
stream_output_path,
"--rngseed", RNGSEED,
"--streams", str(num_streams)]
subprocess.run(gen_stream_cmd, check=True)
def power_test(template_path,
input_path,
stream_path,
report_path,
property_path,
output_path,
warehouse_type):
power_test_cmd = ["./spark-submit-template",
template_path,
"nds_power.py",
input_path,
stream_path,
report_path,
"--input_format", warehouse_type,
"--property_file", property_path]
if output_path:
power_test_cmd.extend(["--output_prefix", output_path])
subprocess.run(power_test_cmd, check=True)
def throughput_test(num_streams,
first_or_second,
template_path,
input_path,
stream_base_path,
report_base_path,
property_path,
warehouse_type):
throughput_cmd = ["./nds-throughput",
get_throughput_stream_nums(num_streams, first_or_second),
"./spark-submit-template",
template_path,
"nds_power.py",
input_path,
stream_base_path + "/query_{}.sql",
report_base_path + "_{}.csv",
"--input_format", warehouse_type,
"--property_file", property_path]
print(throughput_cmd)
subprocess.run(throughput_cmd, check=True)
def maintenance_test(num_streams,
first_or_second,
warehouse_path,
refresh_template_path,
maintenance_raw_data_base_path,
maintenance_query_path,
maintenance_report_base_path,
property_path,
warehouse_type):
refresh_nums = get_stream_range(num_streams, first_or_second)
# refresh run for each stream in Throughput Test.
for i in refresh_nums:
maintenance_raw_path = maintenance_raw_data_base_path + f"_{i}"
maintenance_report_path = maintenance_report_base_path + \
f"_{i}" + ".csv"
maintenance_cmd = ["./spark-submit-template",
refresh_template_path,
"nds_maintenance.py",
warehouse_path,
maintenance_raw_path,
maintenance_query_path,
maintenance_report_path,
"--property_file", property_path,
"--warehouse_type", warehouse_type]
subprocess.run(maintenance_cmd, check=True)
def get_perf_metric(scale_factor, num_streams_in_throughput, Tload, Tpower, Ttt1, Ttt2, Tdm1, Tdm2):
"""get the primary performance metric of benchmark.
note: TPT, TTT, TDM and TLD quantities are in units of decimal hours with a resolution of at least 1/3600th
of an hour (i.e., 1 second)
Args:
scale_factor (str): scale factor
num_streams_in_throughput (int): number of streams executed in a Throughput Test
Tload: time elapse for data loading in seconds
Tpower (float): time elaspe for Power Test in seconds
Ttt1 (float): time elapse for Throughput Test 1 in seconds
Ttt2 (float): time elapse for Throughput Test 2 in seconds
Tdm1 (float): time elapse for Maintenance Test 1 in seconds
Tdm2 (float): time elapse for Maintenance Test 2 in seconds
"""
# Q=Sq*99
Q = num_streams_in_throughput * 99
Tpt = (Tpower * num_streams_in_throughput) / 3600
Ttt = (Ttt1 + Ttt2) / 3600
Tdm = (Tdm1 + Tdm2) / 3600
Tld = (0.01 * num_streams_in_throughput * Tload) / 3600
metric = int(int(scale_factor) * Q / (Tpt*Ttt*Tdm*Tld)**(1/4))
return metric
def write_metrics_report(report_path, metrics_map):
"""write metrics to a csv file at report_path"""
with open(report_path, 'w') as f:
for key, value in metrics_map.items():
f.write(f"{key},{value}\n")
def run_full_bench(yaml_params):
skip_data_gen = yaml_params['data_gen']['skip']
scale_factor = str(yaml_params['data_gen']['scale_factor'])
parallel = str(yaml_params['data_gen']['parallel'])
raw_data_path = yaml_params['data_gen']['raw_data_path']
local_or_hdfs = yaml_params['data_gen']['local_or_hdfs']
# write to Iceberg or DeltaLake
skip_load_test = yaml_params['load_test']['skip']
load_template_path = yaml_params['load_test']['spark_template_path']
warehouse_output_path = yaml_params['load_test']['output_path']
warehouse_type = yaml_params['load_test']['warehouse_type']
load_report_path = yaml_params['load_test']['report_path']
skip_stream_gen = yaml_params['generate_query_stream']['skip']
num_streams = yaml_params['generate_query_stream']['num_streams']
query_template_dir = yaml_params['generate_query_stream']['query_template_dir']
stream_output_path = yaml_params['generate_query_stream']['stream_output_path']
power_stream_path = stream_output_path + "/query_0.sql"
skip_power_test = yaml_params['power_test']['skip']
power_template_path = yaml_params['power_test']['spark_template_path']
power_report_path = yaml_params['power_test']['report_path']
power_property_path = yaml_params['power_test']['property_path']
power_output_path = yaml_params['power_test']['output_path']
skip_throughput_test = yaml_params['throughput_test']['skip']
throughput_report_base = yaml_params['throughput_test']['report_base_path']
# temaplte to write to parquet, with GPU
skip_maintenance_test = yaml_params['maintenance_test']['skip']
# template for refresh functions, requires "spark.sql.catalog.spark_catalog.warehouse"
maintenance_refresh_template = yaml_params['maintenance_test']['maintenance_template_path']
maintenance_query_dir = yaml_params['maintenance_test']['query_dir']
maintenance_report_base_path = yaml_params['maintenance_test']['maintenance_report_base_path']
metrics_report = yaml_params['metrics_report_path']
# 0.
if not skip_data_gen:
run_data_gen(scale_factor, parallel, raw_data_path,
local_or_hdfs, num_streams)
# 1.
if not skip_load_test:
run_load_test(load_template_path,
raw_data_path,
warehouse_output_path,
warehouse_type,
load_report_path)
Tld = round_up_to_nearest_10_percent(float(get_load_time(load_report_path)))
# 2.
if not skip_stream_gen:
# RNGSEED is required for query stream generation in Spec 4.3.1
RNGSEED = get_load_end_timestamp(load_report_path)
gen_streams(num_streams, query_template_dir,
scale_factor, stream_output_path, RNGSEED)
# 3.
if not skip_power_test:
power_test(power_template_path,
warehouse_output_path,
power_stream_path,
power_report_path,
power_property_path,
power_output_path,
warehouse_type)
# TPower is in milliseconds
# But Spec 7.1.16: Elapsed time is measured in seconds rounded up to the nearest 0.1 second.
# Convert it to seconds.
TPower = round_up_to_nearest_10_percent(
float(get_power_time(power_report_path)) / 1000)
# 4.
if not skip_throughput_test:
throughput_test(num_streams,
1,
power_template_path,
warehouse_output_path,
stream_output_path,
throughput_report_base,
power_property_path,
warehouse_type)
Ttt1 = get_throughput_time(throughput_report_base,
num_streams, 1)
# 5
if not skip_maintenance_test:
maintenance_test(num_streams,
1,
warehouse_output_path,
maintenance_refresh_template,
raw_data_path,
maintenance_query_dir,
maintenance_report_base_path,
power_property_path,
warehouse_type)
Tdm1 = get_maintenance_time(maintenance_report_base_path,
num_streams,
1)
# 6
if not skip_throughput_test:
throughput_test(num_streams,
2,
power_template_path,
warehouse_output_path,
stream_output_path,
throughput_report_base,
power_property_path,
warehouse_type)
Ttt2 = get_throughput_time(throughput_report_base,
num_streams, 2)
# 7
if not skip_maintenance_test:
maintenance_test(num_streams,
2,
warehouse_output_path,
maintenance_refresh_template,
raw_data_path,
maintenance_query_dir,
maintenance_report_base_path,
power_property_path,
warehouse_type)
Tdm2 = get_maintenance_time(maintenance_report_base_path,
num_streams,
2)
perf_metric = get_perf_metric(
scale_factor, num_streams//2, Tld, TPower, Ttt1, Ttt2, Tdm1, Tdm2)
print(f"====== Performance Metric: {perf_metric} ======")
metrics_map = {"scale_factor": scale_factor,
"num_streams": num_streams,
"Tld": Tld,
"TPower": TPower,
"Ttt1": Ttt1,
"Ttt2": Ttt2,
"Tdm1": Tdm1,
"Tdm2": Tdm2,
"perf_metric": perf_metric}
write_metrics_report(metrics_report, metrics_map)
if __name__ == "__main__":
parser = parser = argparse.ArgumentParser()
parser.add_argument('yaml_config',
help='yaml config file for the benchmark')
args = parser.parse_args()
params = get_yaml_params(args.yaml_config)
run_full_bench(params)