-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
346 lines (282 loc) · 13.9 KB
/
stats.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
#!/usr/bin/env python3
### Transform data distribution into statistics data
import json
import io
import math
import matplotlib.cbook as cbook
import matplotlib.colors as col
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import os
# from os import path
import pandas as pd
import re
import string
import sys
### local import
import utils
##########
########## Parsing utils
##########
OPERATIONS_SORTED_LIST = [
("avg", lambda x: sum([v for v in x]) / len(x) if len(x) > 0 else np.nan),
("std", lambda x: np.std(x) if len(x) > 0 else np.nan),
("min", lambda x: x[0] if len(x) > 0 else np.nan),
("1th", lambda x: quantile(x, 0.01) if len(x) > 0 else np.nan),
("5th", lambda x: quantile(x, 0.05) if len(x) > 0 else np.nan),
("10th", lambda x: quantile(x, 0.10) if len(x) > 0 else np.nan),
("25th", lambda x: quantile(x, 0.25) if len(x) > 0 else np.nan),
("50th", lambda x: quantile(x, 0.50) if len(x) > 0 else np.nan),
("75th", lambda x: quantile(x, 0.75) if len(x) > 0 else np.nan),
("90th", lambda x: quantile(x, 0.90) if len(x) > 0 else np.nan),
("95th", lambda x: quantile(x, 0.95) if len(x) > 0 else np.nan),
("99th", lambda x: quantile(x, 0.99) if len(x) > 0 else np.nan),
("max", lambda x: x[len(x) - 1] if len(x) > 0 else np.nan),
]
# quantile function with ordered list (much faster than np.quantile)
# From https://stackoverflow.com/questions/2374640/how-do-i-calculate-percentiles-with-python-numpy
def quantile(N, percent, key=lambda x:x):
"""
Find the quantile of a list of values.
@parameter N - is a list of values. Note N MUST BE already sorted.
@parameter percent - a float value from 0.0 to 1.0.
@parameter key - optional key function to compute value from each element of N.
@return - the quantile of the values
"""
if not N:
return None
k = (len(N)-1) * percent
f = math.floor(k)
c = math.ceil(k)
if f == c:
return key(N[int(k)])
d0 = key(N[int(f)]) * (c-k)
d1 = key(N[int(c)]) * (k-f)
return d0+d1
### Add a column to a dataframe per stat function for a given distribution
def addStatsColumns(df, columnPrefix, distribution):
sortedDistribution = sorted(distribution)
for label, function in OPERATIONS_SORTED_LIST:
column = "{} {}".format(columnPrefix, label)
df[column] = function(sortedDistribution)
##########
########## Parsing
##########
def parseChopchopGeneric(csvPrefix, throughputFile, latencyFile):
"""
The two input files should have the same systems and workloads.
Generates a csv with header ",system,workload,[op stats],[lat stats]".
One row per workload. One csv file per system.
"""
### Read input files
throughput = None
latency = None
with open(throughputFile) as f:
throughput = json.load(f)
with open(latencyFile) as f:
latency = json.load(f)
### One dataframe per system/baseline
for system in throughput:
dfOut = pd.DataFrame()
for workloadIndex, workload in enumerate(throughput[system]):
### Make a row per workload and fill it with many stats
dfRow = pd.DataFrame(index=[workloadIndex])
dfRow["system"] = "cc-{}".format(system)
dfRow["workload"] = float(workload) * 10**6 # Uniformize units: Mop/s -> op/s
### Uniformize units: M op/s -> op/s
throughputs = [round(v * 10**6) for v in throughput[system][workload]]
### Add a column per stat function for each distribution
addStatsColumns(dfRow, "op", throughputs)
addStatsColumns(dfRow, "lat", latency[system][workload])
dfOut = pd.concat([dfOut, dfRow])
# print(dfOut["lat avg"])
fileOut = utils.DIR_STATS + "/{}-chopchop-{}.csv".format(csvPrefix, system)
dfOut.to_csv(fileOut)
print("Generated {}".format(fileOut))
def parseBaselinesGeneric(csvPrefix, parameterKey, system, dataDir, latencyFactor=10**3, withByteRate=False):
"""
The input dataDir contains one directory per workload/payload, each of which contains
one json file per run. Generates a csv with header
",system,workload|payload,[op stats],[lat stats]". One row per workload|payload.
"""
### Find dirs that have the right prefix
# dataDirPath = os.path.join(os.path.dirname(sys.argv[0]), dataDir)
dataDirPath = os.path.abspath(dataDir)
dirs = []
with os.scandir(dataDirPath) as it:
for entry in it:
if entry.name.startswith(parameterKey) and entry.is_dir():
dirs.append(entry.path)
dirs = sorted(dirs)
### Parse the dirs to load all jsons
allData = {}
for dirPath in dirs:
dirName = os.path.basename(dirPath)
parameter = re.sub("{}-".format(parameterKey), "", dirName)
parameter = int(parameter)
### Fill data structure with each run's json
allData[parameter] = []
with os.scandir(dirPath) as it:
# print(dirPath)
for entry in it:
if entry.name.endswith('.json') and entry.is_file():
# print("{}/{}".format(dirPath,entry.name))
with open(entry.path) as f:
allData[parameter].append(json.load(f))
### Fill dataframe used for csv output
dfOut = pd.DataFrame()
for parameterIndex, parameter in enumerate(allData):
# Make a row per parameter value and fill it with many stats
dfRow = pd.DataFrame(index=[parameterIndex])
dfRow["system"] = system
dfRow[parameterKey] = parameter
### Add the average throughput column, the only one available :(
throughputs = []
for run in allData[parameter]:
throughputs.append(run["throughput-avg"])
dfRow["op avg"] = np.mean(throughputs)
### Aggregate all latency values and add a column per stat function
latencies = []
for run in allData[parameter]:
for singleValue in run["latency"]:
# Uniformize units: seconds -> milliseconds
latencies.append(singleValue * latencyFactor)
addStatsColumns(dfRow, "lat", latencies)
### Only linerate files contain server byte rates
if withByteRate:
outputRateOp = []
outputRateBytes = []
goodputRatios = []
goodputRateOp = []
goodputRateBytes = []
for run in allData[parameter]:
### Don't use whole distribution in the end since goodputRateOp is only avg
# byterates.append(run["server-byterate"])
### Warning dark magic. Easier to understand in parseLinerateChopchop
go = run["throughput-avg"]
### Ideal payload size = 11.5; actual payload size = 88
gb = go * 11.5
ob = run["server-byterate-avg"]
gr = gb / ob
oo = go / gr
# print(ob)
outputRateOp.append(oo)
outputRateBytes.append(ob)
goodputRatios.append(gr)
goodputRateOp.append(go)
goodputRateBytes.append(gb)
dfRow["output rate op avg"] = np.mean(outputRateOp)
dfRow["output rate B avg"] = np.mean(outputRateBytes)
dfRow["goodput ratio avg"] = np.mean(goodputRatios)
dfRow["goodput rate op avg"] = np.mean(goodputRateOp) # = dfRow["op avg"]
dfRow["goodput rate B avg"] = np.mean(goodputRateBytes)
dfOut = pd.concat([dfOut, dfRow])
fileOut = utils.DIR_STATS + "/{}-{}.csv".format(csvPrefix, system)
dfOut.to_csv(fileOut)
print("Generated {}".format(fileOut))
def parseServerFaults(throughputFile, latencyFile):
### Read input files
throughput = None
latency = None
with open(throughputFile) as f:
throughput = json.load(f)
with open(latencyFile) as f:
latency = json.load(f)
### Prepare to add number of faults in output
faultLabels = ["threshold", "1"]
### One dataframe per system/baseline
for system in throughput:
dfOut = pd.DataFrame()
for workloadIndex, workload in enumerate(throughput[system]):
# Make a row per workload and fill it with many stats
dfRow = pd.DataFrame(index=[workloadIndex])
dfRow["system"] = "cc-{}".format(system)
dfRow["nb-faults"] = faultLabels[workloadIndex]
dfRow["workload"] = float(workload) * 10**6 # Uniformize units: MB -> B
### Uniformize units: M op/s -> op/s
throughputs = [round(v * 10**6) for v in throughput[system][workload]]
### Add a column per stat function for each distribution
addStatsColumns(dfRow, "op", throughputs)
addStatsColumns(dfRow, "lat", latency[system][workload])
dfOut = pd.concat([dfOut, dfRow])
# print(dfOut)
fileOut = utils.DIR_STATS + "/faults-chopchop-{}.csv".format(system)
dfOut.to_csv(fileOut)
print("Generated {}".format(fileOut))
def parseLinerateChopchop(file):
### Read input file
data = None
with open(file) as f:
data = json.load(f)
### One dataframe per system/baseline
for system in data:
dfOut = pd.DataFrame()
for inputThroughputIndex, inputThroughput in enumerate(data[system]):
### Make a row per workload and fill it with many stats
dfRow = pd.DataFrame(index=[inputThroughputIndex])
dfRow["system"] = "cc-{}".format(system)
dfRow["input"] = float(inputThroughput) * 10**6 # Uniformize units: Mop/s -> op/s
### Collect and sort distributions, recompute other metrics for plots
outputRateOp = []
outputRateBytes = []
goodputRatios = []
goodputRateOp = []
goodputRateBytes = []
for entry in data[system][inputThroughput]:
### The column "output_throughput" actually contains the goodput (names can be confusing here)
go = float(entry["output_throughput"]) * 10**6 # Uniformize units: Mop/s -> op/s
gb = 11.5 * go # 11.5 = 8 bytes of payload + 3.5 bytes of id
gr = entry["goodput"] # Goodput ratio
oo = go / gr # Recompute the goodput in op/s from the ratio
ob = 11.5 * oo
outputRateOp.append(oo)
outputRateBytes.append(ob)
goodputRatios.append(gr)
goodputRateOp.append(go)
goodputRateBytes.append(gb)
### Add a column per stat function for each distribution
addStatsColumns(dfRow, "output rate op", outputRateOp)
addStatsColumns(dfRow, "output rate B", outputRateBytes)
addStatsColumns(dfRow, "goodput ratio", goodputRatios)
addStatsColumns(dfRow, "goodput rate op", goodputRateOp)
addStatsColumns(dfRow, "goodput rate B", goodputRateBytes)
dfOut = pd.concat([dfOut, dfRow])
# print(system)
# print(dfOut["op avg"])
print(dfOut["goodput ratio avg"])
# print(dfOut)
fileOut = utils.DIR_STATS + "/linerate-chopchop-{}.csv".format(system)
dfOut.to_csv(fileOut)
print("Generated {}".format(fileOut))
#####
##### Main
#####
if __name__ == "__main__":
### Comma plot
parseChopchopGeneric("comma", utils.DIR_DATA + "/comma-chopchop-throughput.json", utils.DIR_DATA + "/comma-chopchop-latency.json")
parseBaselinesGeneric("comma", "workload", "bullshark", utils.DIR_DATA + "/comma-64-bullshark")
parseBaselinesGeneric("comma", "workload", "bullshark-sig", utils.DIR_DATA + "/comma-64-bullshark-sig")
parseBaselinesGeneric("comma", "workload", "bftsmart", utils.DIR_DATA + "/comma-64-bftsmart", latencyFactor=1) # bftsmart is already in millisec, no need to multiply
parseBaselinesGeneric("comma", "workload", "hotstuff", utils.DIR_DATA + "/comma-64-hotstuff")
### Server faults plot
parseServerFaults(utils.DIR_DATA + "/faults-throughput.json", utils.DIR_DATA + "/faults-latency.json")
### Applications plot
for app in ["auction", "payment", "pixelwar"]:
parseChopchopGeneric("app-{}".format(app), utils.DIR_DATA + "/app-{}-throughput.json".format(app), utils.DIR_DATA + "/app-{}-latency.json".format(app))
### Payload sizes plot
for size in ["032", "128", "512"]:
parseChopchopGeneric("payload-{}".format(size), utils.DIR_DATA + "/payload-{}-throughput.json".format(size), utils.DIR_DATA + "/payload-{}-latency.json".format(size))
parseBaselinesGeneric("payload-{}".format(size), "payload", "bullshark-sig", utils.DIR_DATA + "/payload-sizes-bullshark-sig-{}".format(size))
### System sizes plot
for size in ["08", "16", "32"]:
parseChopchopGeneric("system-{}".format(size), utils.DIR_DATA + "/system-{}-throughput.json".format(size), utils.DIR_DATA + "/system-{}-latency.json".format(size))
parseBaselinesGeneric("system-{}".format(size), "system", "bullshark-sig", utils.DIR_DATA + "/system-sizes-bullshark-sig-{}".format(size))
### Reduction plot when clients crash
parseChopchopGeneric("reduction-00", utils.DIR_DATA + "/reduction-0-throughput.json", utils.DIR_DATA + "/reduction-0-latency.json")
### Linerate plot
parseLinerateChopchop(utils.DIR_DATA + "/linerate-chopchop.json")
parseBaselinesGeneric("linerate", "workload", "bullshark-sig", utils.DIR_DATA + "/linerate-64-bullshark-sig", withByteRate=True)
### Matching trusted and untrusted CPU for bullshark
parseChopchopGeneric("matching-trusted-192", utils.DIR_DATA + "/matching-trusted-throughput.json", utils.DIR_DATA + "/matching-trusted-latency.json")
parseBaselinesGeneric("matching-trusted-192", "system", "bullshark-sig", utils.DIR_DATA + "/matching-trusted-bullshark-sig")