-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththroughput.py
executable file
·202 lines (148 loc) · 5.12 KB
/
throughput.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
#!/usr/bin/env python3
from os import listdir
from os.path import isfile, join
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
METRICS_DIR = "logs/3"
PLOT_DIR = "plots"
PROTOCOL = "VCD"
XRANGE = 250
YRANGE = 900
PLOT_SMOOTH = False
SMOOTHNESS = 500
def read(f):
"""
Read from file and separate entries by ,
and parts of each entry by -
"""
r = []
with open(f, "r") as fd:
for line in fd:
parts = line.strip().split("-")
r.append(parts)
return r
def ms_to_s(ms):
"""
Convert a string timestamp in milliseconds to seconds.
"""
return int(int(ms) / 1000)
def main():
# assumes there's a single execution (e.g. only for 128 clients)
files = [join(METRICS_DIR, f) for f in listdir(METRICS_DIR)]
files = [f for f in files if isfile(f) and PROTOCOL in f]
# save cluster -> (ts -> size)
data = {}
for f in files:
# get cluster name
parts = f.split("-")
cluster = parts[2] + "-" + parts[3]
if "chains" in f:
# init cluster
data[cluster] = {}
# get chains
for ts, size in read(f):
# convert them to integers
ts = int(ts)
size = int(size)
# store all sizes from the same timestamp
if not ts in data[cluster]:
data[cluster][ts] = []
data[cluster][ts].append(size)
if "events" in f:
# there's a single events file
metrics = {}
# read file
read_f = read(f)
_, _, seqs, tss = list(zip(*read_f))
# convert seqs and tss to int
seqs = list(map(int, seqs))
tss = list(map(int, tss))
# get min seq and min ts (in millisecond)
min_seq = min(seqs)
min_ts = min(tss)
# get metrics
for what, sender, seq, ts in read_f:
# compute seq and ts
seq = int(seq) - min_seq
ts = int(ts) - min_ts
# create event name
name = "(" + sender + "," + str(seq) + ") by " + cluster
# create event if it doesn't exist
if not name in metrics:
metrics[name] = {}
# append event
metrics[name][ts] = what
# save [(event, start, end)]
events = []
for name in metrics:
[start, end] = sorted(metrics[name])
assert metrics[name][start] == "recover_start"
assert metrics[name][end] == "recover_end"
# add to events
events.append((start, end, name))
# plot events
plot_events(events)
# aggregate per ranges of timestamps
aggregate = {}
for cluster, ts_to_sizes in data.items():
# init cluster
aggregate[cluster] = {}
print("Processing " + cluster + "...")
# get min and max ts
min_ts = ms_to_s(min(ts_to_sizes.keys()))
max_ts = ms_to_s(max(ts_to_sizes.keys()))
for i in range(min_ts, max_ts + 1):
# tput = sum values of the map
# s.t. its key mapped to second is the current second 's'
tput = sum([sum(sizes) for ts, sizes in ts_to_sizes.items() if ms_to_s(ts) == i])
# subtract initial ts from i
ts = i - min_ts
# store data point
aggregate[cluster][ts] = tput
# plot aggregate data
for cluster, ts_to_size in aggregate.items():
# plot data
x = np.array(list(ts_to_size.keys()))
y = np.array(list(ts_to_size.values()))
plot_tput(x, y, cluster, cluster + ".png")
# plot smooth data
if PLOT_SMOOTH:
x_smooth = np.linspace(x.min(), x.max(), SMOOTHNESS)
y_smooth = spline(x, y, x_smooth)
plot_tput(x_smooth, y_smooth, cluster + " (smooth)", cluster + "_smooth.png")
def plot_events(events):
# sort events
events = list(reversed(sorted(events)))
# [width, height]
params = plt.rcParams["figure.figsize"]
plt.rcParams["figure.figsize"] = [12, 40]
# compute y range
yrange = range(len(events))
(starts, ends, names) = list(zip(*events))
# compute widths
widths = [e - s for s, e in zip(starts, ends)]
# init plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
# add plot
ax.barh(yrange, widths, left=starts)
ax.set(xlabel="time (ms)", ylabel="dots recovered")
plt.yticks(yrange, names)
fig.savefig(join(PLOT_DIR, PROTOCOL + "_events.png"))
# restore params
plt.rcParams["figure.figsize"] = params
def plot_tput(x, y, title, output):
# init plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
# configure range on axis
axis = plt.gca()
axis.set_xlim([0, XRANGE])
axis.set_ylim([0, YRANGE])
# add plot
ax.plot(x, y)
ax.set(xlabel="time (s)", ylabel="tput (ops/s)", title=title)
fig.savefig(join(PLOT_DIR, PROTOCOL + "_" + output))
if __name__ == "__main__":
main()