-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq_rate.py
158 lines (131 loc) · 4.28 KB
/
req_rate.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
""" plot request rate
usage:
1. run traceAnalyzer: `./traceAnalyzer /path/trace trace_format --common`,
this will generate some output, including request rate result, trace.reqRate
2. plot request rate using this script:
`python3 req_rate.py trace.reqRate_w300`
"""
import os, sys
import re
import numpy as np
import matplotlib.pyplot as plt
from typing import List, Dict, Tuple
import logging
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from utils.trace_utils import extract_dataname
from utils.plot_utils import FIG_DIR, FIG_TYPE, get_colors, get_linestyles
logger = logging.getLogger("req_rate")
def _load_req_rate_data(
datapath: str,
) -> Tuple[List[float], List[float], List[float], List[float], int]:
"""load request rate plot data from C++ computation
Args:
datapath: path to the reqRate data file
Return:
req_rate_list: list of request rate
"""
ifile = open(datapath)
data_line = ifile.readline()
line = ifile.readline()
assert (
"# req rate - time window" in line
), "the input file might not be reqRate data file"
time_window = int(line.split()[6].strip("()s "))
req_rate_list = [float(i) for i in ifile.readline().split(",")[:-1]]
assert "byte rate" in ifile.readline()
byte_rate_list = [float(i) for i in ifile.readline().split(",")[:-1]]
assert "obj rate" in ifile.readline()
obj_rate_list = [float(i) for i in ifile.readline().split(",")[:-1]]
assert "first seen obj (cold miss) rate" in ifile.readline()
new_obj_rate_list = [float(i) for i in ifile.readline().split(",")[:-1]]
ifile.close()
assert len(req_rate_list) == len(byte_rate_list)
assert len(req_rate_list) == len(obj_rate_list) == len(new_obj_rate_list)
return req_rate_list, byte_rate_list, obj_rate_list, new_obj_rate_list, time_window
def plot_req_rate(datapath: str, figname_prefix: str = ""):
COLOR = get_colors(2)
if len(figname_prefix) == 0:
figname_prefix = extract_dataname(datapath)
(
req_rate_list,
byte_rate_list,
obj_rate_list,
new_obj_rate_list,
time_window,
) = _load_req_rate_data(datapath)
plt.plot(
[i * time_window / 3600 for i in range(len(req_rate_list))],
[r / 1000 for r in req_rate_list],
label="request",
color=COLOR[0],
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Request rate (KQPS)")
plt.grid(linestyle="--")
plt.savefig(
"{}/{}_reqRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"request rate saved as {}/{}_reqRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
plt.plot(
[i * time_window / 3600 for i in range(len(byte_rate_list))],
[n_byte / 1024 / 1024 for n_byte in byte_rate_list],
label="byte",
color=COLOR[0],
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Request rate (Mbps)")
plt.grid(linestyle="--")
plt.savefig(
"{}/{}_byteRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"byte request rate saved as {}/{}_byteRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
plt.plot(
[i * time_window / 3600 for i in range(len(obj_rate_list))],
obj_rate_list,
label="object",
color=COLOR[0],
linestyle="-",
linewidth=1,
)
plt.plot(
[i * time_window / 3600 for i in range(len(new_obj_rate_list))],
new_obj_rate_list,
label="new object",
color=COLOR[1],
linestyle="--",
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Object rate (QPS)")
plt.grid(linestyle="--")
plt.legend()
plt.savefig(
"{}/{}_objRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"object request rate saved as {}/{}_objRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
if __name__ == "__main__":
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("datapath", type=str, help="data path")
p = ap.parse_args()
plot_req_rate(p.datapath)