-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsd_intervals.py
163 lines (147 loc) · 4.92 KB
/
fsd_intervals.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
import bisect
from analysis import *
import argparse
import matplotlib
from matplotlib import rcParams
rcParams.update(
{
"font.family": "serif",
"mathtext.fontset": "stix",
"font.serif": ["SimSun"],
"axes.unicode_minus": False,
}
)
ticklabel_style = {
"fontname": "Times New Roman",
}
parser = argparse.ArgumentParser(description="draw flow slowdown in each interval under various load")
parser.add_argument(
"-c",
"--csv",
dest="csv",
help="experiment configure name",
type=str,
metavar="csv_path",
required=True,
)
parser.add_argument(
"-l",
"--legend",
dest="legendname",
help="which legends to plot",
choices=["epsion", "policy"],
type=str,
metavar="legend_name",
default="epsion",
)
parser.add_argument(
"-p",
"--percentile",
dest="percentile",
type=float,
metavar="percentile",
default=0.95,
)
args = parser.parse_args()
output_name = "fsd_intervals_" + args.legendname + ".pdf"
percentile_lowerbound = args.percentile
print("-" * 10, "reading data", "-" * 10)
sheet = read_csv(args.csv, True)
_kept_rows = ["flowSize:vector", "fct:vector", "idealFct:vector", "jobRCT:vector"]
flows = get_vectors(
sheet,
names=_kept_rows,
module="FatTree",
)
runs = get_runIDs(sheet, by="iterationvars")
assert isinstance(runs, dict)
print("-" * 10, "align flow and job finish time", "-" * 10)
truncate_vectime(flows, runs)
print("-" * 10, "calc slowdown", "-" * 10)
df = get_flows_slowdown(flows, runs)
policies = sorted(list(set([extract_str(x, "aggPolicy") for x in runs.keys()])))
epsions = sorted(list(set([extract_float(x, "epsion") for x in runs.keys()])))
loads = sorted(list(set([extract_float(x, "load") for x in runs.keys()])))
legends = []
if args.legendname == "epsion":
legends = epsions
elif args.legendname == "policy":
legends = policies
loads = [0.1, 0.5, 0.9]
plt.rcParams["font.family"] = "Serif"
fig, ax = plt.subplots(len(loads), 1, figsize=(12 / 2.54, 21 / 2.54))
_pos = np.arange(1, 11) * (len(epsions) + 1)
_bar_width = 0.8
print("-" * 10, "flows count in each interval", "-" * 10)
dist = "./src/distribution/data/FbHdp_10percentile.csv"
distper = pd.read_csv(dist)
print(distper["xtick"].values)
row_index = 0
for load in loads:
current_load = df[(df["load"] == load)]
bps = []
for step, legend in enumerate(legends):
print(load, legend)
current_data = current_load[current_load[args.legendname] == legend]
flsz = current_data.iloc[0, :]["flowsize"]
flsz.sort()
x = []
for fs in distper["flowsize"]:
x.append(bisect.bisect_left(flsz, fs))
x = [0] + x
x95 = []
flsd: np.ndarray = current_data["slowdown"].values[0]
flsd_intv = []
flsd_intv_data = []
flct = []
for l, r in itertools.pairwise(x):
lb = round(l + (r - l) * percentile_lowerbound)
x95.append((lb, r))
if len(flsd[lb:r]) == 0:
print_error(f"inval too small: {lb},{r}")
exit()
data = flsd[lb:r]
flsd_intv.append(data.mean())
flsd_intv_data.append(data)
flct.append(len(data))
print(flct)
# bp = ax[col_index].plot(_pos, flsd_intv, color=COLORS[step], marker=MARKERS[step])
bp = ax[row_index].bar(
_pos + step * _bar_width, flsd_intv, _bar_width, hatch=HATCHES[step], color=COLORS[step], ec="black"
)
# bp = ax[col_index].boxplot(
# flsd_intv_data,
# False,
# "",
# widths=0.4,
# patch_artist=True,
# positions=_pos + step,
# boxprops=dict(facecolor=COLORS[step]),
# )
bps.append(bp)
# * xticks set only once each ax
ax[row_index].set_xticks(_pos + _bar_width / 2, distper["xtick"])
# ax[col_index].legend([b["boxes"][0] for b in bps], epsions)
if args.legendname == "epsion":
ax[row_index].legend(
[b[0] for b in bps],
[f"K={0 if legend == 0.0 else 10}" for legend in legends],
frameon=False,
prop={"family": "Times New Roman"},
)
elif args.legendname == "policy":
ax[row_index].legend([b[0] for b in bps], ["ATP", "ATSR"], frameon=False, prop={"family": "Times New Roman"})
ax[row_index].set_xlabel(f"流长度( 负载{load} )")
ax[row_index].set_ylabel("95百分位流slowdown")
ax[row_index].set_axisbelow(True)
ax[row_index].yaxis.grid(color="gray", linestyle="dashed", alpha=0.4)
ax[row_index].xaxis.grid(color="gray", linestyle="dashed", alpha=0.4)
row_index += 1
# ax[0].set_ylabel("95百分位流slowdown")
fig.subplots_adjust(left=0.1, bottom=0.05, right=0.99, top=0.99)
# fig.subplots_adjust(hspace=0.3)
fig.savefig(output_name, dpi=600)
print(f"output {output_name}")
import os
paper_path = os.path.join(os.getcwd(), f"./{output_name}")
fig.savefig(paper_path, dpi=600)