|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | + |
| 5 | + |
| 6 | +def process_json_files(dirname: str, prefix: str = ""): |
| 7 | + workers_arr = [] |
| 8 | + autobatching_arr = [] |
| 9 | + tensorbatching_arr = [] |
| 10 | + workers_autobatching_table_p50 = {} |
| 11 | + workers_autobatching_table_rps = {} |
| 12 | + workers_tensorbatching_table_p50 = {} |
| 13 | + workers_tensorbatching_table_rps = {} |
| 14 | + files_list = os.listdir(dirname) |
| 15 | + for fname in files_list: |
| 16 | + if ".json" in fname and ((prefix != "" and prefix in fname) or (prefix == "")): |
| 17 | + full_fname = "{}/{}".format(dirname, fname) |
| 18 | + with open(full_fname) as json_file: |
| 19 | + dd = json.load(json_file) |
| 20 | + workers = dd["Workers"] |
| 21 | + autobatching = dd["MetadataAutobatching"] |
| 22 | + tensorbatching = dd["TensorBatchSize"] |
| 23 | + rps = dd["OverallRates"]["overallOpsRate"] |
| 24 | + p50 = dd["OverallQuantiles"]["AllQueries"]["q50"] |
| 25 | + |
| 26 | + # we fix the tensor batch size to 1 for autobatching |
| 27 | + if tensorbatching == 1: |
| 28 | + process_table_datapoint(autobatching, autobatching_arr, p50, workers, workers_arr, |
| 29 | + workers_autobatching_table_p50, full_fname) |
| 30 | + process_table_datapoint(autobatching, autobatching_arr, rps, workers, workers_arr, |
| 31 | + workers_autobatching_table_rps, full_fname) |
| 32 | + # we fix autobatching to 0 when doing tensor batching |
| 33 | + if autobatching == 0: |
| 34 | + process_table_datapoint(tensorbatching, tensorbatching_arr, p50, workers, workers_arr, |
| 35 | + workers_tensorbatching_table_p50, full_fname) |
| 36 | + process_table_datapoint(tensorbatching, tensorbatching_arr, rps, workers, workers_arr, |
| 37 | + workers_tensorbatching_table_rps, full_fname) |
| 38 | + |
| 39 | + workers_arr.sort() |
| 40 | + autobatching_arr.sort() |
| 41 | + tensorbatching_arr.sort() |
| 42 | + return workers_arr, autobatching_arr, workers_autobatching_table_rps, workers_autobatching_table_p50, tensorbatching_arr, workers_tensorbatching_table_rps, workers_tensorbatching_table_p50 |
| 43 | + |
| 44 | + |
| 45 | +def process_table_datapoint(metric_key, metric_arr, metric_value, workers, workers_arr, table, fname): |
| 46 | + metric_key_fname = "{}-fname".format(metric_key) |
| 47 | + if workers not in workers_arr: |
| 48 | + workers_arr.append(workers) |
| 49 | + if metric_key not in metric_arr: |
| 50 | + metric_arr.append(metric_key) |
| 51 | + if workers not in table: |
| 52 | + table[workers] = {} |
| 53 | + if metric_key not in table[workers]: |
| 54 | + table[workers][metric_key] = [] |
| 55 | + table[workers][metric_key_fname] = [] |
| 56 | + table[workers][metric_key].append(metric_value) |
| 57 | + table[workers][metric_key_fname].append(fname) |
| 58 | + |
| 59 | + |
| 60 | +def print_results_table(workers_arr, metric_arr, metric_table, metric_str, functor=min, |
| 61 | + print_last_server_runtime_stats=True, server_runtime_stats_metricname="used_memory_human"): |
| 62 | + print("Workers,{}".format(",".join(["{} {}".format(metric_str, x) for x in metric_arr]))) |
| 63 | + for workersN in workers_arr: |
| 64 | + line = ["{} workers".format(workersN)] |
| 65 | + for metric_key in metric_arr: |
| 66 | + v = "n/a" |
| 67 | + metric_key_fname = "{}-fname".format(metric_key) |
| 68 | + if metric_key in metric_table[workersN]: |
| 69 | + v = functor(metric_table[workersN][metric_key]) |
| 70 | + index = metric_table[workersN][metric_key].index(v) |
| 71 | + fname = metric_table[workersN][metric_key_fname][index] |
| 72 | + if print_last_server_runtime_stats: |
| 73 | + runtime_stats_metric = "n/a" |
| 74 | + with open(fname) as json_file: |
| 75 | + dd = json.load(json_file) |
| 76 | + server_runtime_stats = dd["ServerRunTimeStats"] |
| 77 | + ts = list(server_runtime_stats.keys()) |
| 78 | + if len(ts) > 0: |
| 79 | + last_stat_key = ts[-1] |
| 80 | + first_host = list(server_runtime_stats[last_stat_key].keys())[0] |
| 81 | + runtime_stats_metric = server_runtime_stats[last_stat_key][first_host][ |
| 82 | + server_runtime_stats_metricname] |
| 83 | + v = '{}'.format(runtime_stats_metric) |
| 84 | + |
| 85 | + line.append(v) |
| 86 | + print(",".join([str(x) for x in line])) |
| 87 | + |
| 88 | + |
| 89 | +parser = argparse.ArgumentParser( |
| 90 | + description="Simple script to process RedisAI results JSON and output overall metrics", |
| 91 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 92 | +) |
| 93 | +parser.add_argument("--dir", type=str, required=True) |
| 94 | +parser.add_argument("--prefix", type=str, default="", help="prefix to filter the result files by") |
| 95 | +parser.add_argument("--server_runtime_stats_metricname", type=str, default="used_memory_human", |
| 96 | + help="The server runtime stat metric to extract from the last available datapoint per test") |
| 97 | +args = parser.parse_args() |
| 98 | + |
| 99 | +workers_arr, autobatching_arr, workers_autobatching_table_rps, workers_autobatching_table_p50, tensorbatching_arr, workers_tensorbatching_table_rps, workers_tensorbatching_table_p50 = process_json_files( |
| 100 | + args.dir, args.prefix) |
| 101 | +print("-------------------") |
| 102 | +print("Using the Overall inferences/sec to decide which result is the best per test variation") |
| 103 | +print("-------------------") |
| 104 | +print("## Auto-batching {} variation".format(args.server_runtime_stats_metricname)) |
| 105 | +print_results_table(workers_arr, autobatching_arr, workers_autobatching_table_rps, "Auto-batching", max, True, |
| 106 | + args.server_runtime_stats_metricname) |
| 107 | +print("") |
| 108 | +print("-------------------") |
| 109 | +print("## Tensor-batching {} variation".format(args.server_runtime_stats_metricname)) |
| 110 | +print_results_table(workers_arr, tensorbatching_arr, workers_tensorbatching_table_rps, "Tensor-batching", max, True, |
| 111 | + args.server_runtime_stats_metricname) |
| 112 | +print("") |
0 commit comments