-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyzer.py
289 lines (224 loc) · 6.93 KB
/
analyzer.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
import math
import json
import sys
import re
from pprint import pprint
if len(sys.argv) < 2:
print('Usage: python analyzer.py <path/to/log> [<detail_level=0>]')
sys.exit(-1)
def avg(datalist):
if len(datalist) == 0:
return 0
return sum(datalist) / len(datalist)
def join2(datalist, joinstr=' '):
return joinstr.join([str(d) for d in datalist])
def stdd(datalist):
avg_n = avg(datalist)
v = avg([(d - avg_n) ** 2 for d in datalist])
return math.sqrt(v)
def percentile(num, total):
return '%d%%' % (num / total * 100)
with open(sys.argv[1], 'r') as file:
log = file.readlines()
DETAIL_LEVEL = 0
if len(sys.argv) == 3 :
DETAIL_LEVEL = int(sys.argv[2])
NUM_NODES = 8
LOG_FORMAT = re.compile('(\S+)\s(\S+)\s(\d+)\s(\d+)\s(\S+)\s(.+)')
std_time = math.inf
last_time = -1
records = []
# Parse log
# for row in log[20:-20]:
for row in log:
if len(row) <= 1:
continue
matches = LOG_FORMAT.search(row)
start_time = int(matches.group(3))
end_time = int(matches.group(4))
function_name = matches.group(5)
data = json.loads(matches.group(6))
if 'Error' in data:
continue
std_time = min(std_time, start_time)
last_time = max(last_time, end_time)
records.append((
start_time,
end_time,
function_name,
data,
))
# ret = [{} for _ in range(0, NUM_NODES)]
max_timeslot = int((last_time - std_time) / 1000) + 1
ret = []
for _ in range(0, NUM_NODES):
arr = []
for _ in range(0, max_timeslot):
arr.append({})
ret.append(arr)
# Init data structures
durations = []
latencies = []
durations_per_functions = {}
latencies_per_functions = {}
num_total = 0
num_image_hit = 0
opt1_execution_times = ([], [])
opt1_latencies = ([], [])
num_using_pooled_container = 0
opt2_execution_times = ([], [])
opt2_latencies = ([], [])
num_using_existing_rest_container = 0
opt3_execution_times = ([], [])
opt3_latencies = ([], [])
executions_per_node = [{} for _ in range(0, NUM_NODES)]
algorithm_latencies = []
for start_time, end_time, function_name, data in records:
s = math.floor((start_time - std_time) / 1000)
e = math.ceil((end_time - std_time) / 1000)
node_id = data['LoadBalancingInfo']['WorkerNodeId']
for i in range(s, e):
ret[node_id][i][function_name] = ret[node_id][i].get(function_name, 0) + 1
duration = end_time - start_time
latency = duration - data['InternalExecutionTime']
if function_name not in durations_per_functions:
durations_per_functions[function_name] = []
latencies_per_functions[function_name] = []
durations_per_functions[function_name].append(duration)
latencies_per_functions[function_name].append(latency)
durations.append(duration)
latencies.append(latency)
algorithm_latencies.append(data['LoadBalancingInfo']['AlgorithmLatency'])
num_total += 1
if data['Meta']['ImageBuilt']:
opt1_execution_times[1].append(duration)
opt1_latencies[1].append(latency)
else:
num_image_hit += 1
opt1_execution_times[0].append(duration)
opt1_latencies[0].append(latency)
if data['Meta']['UsingPooledContainer']:
num_using_pooled_container += 1
opt2_execution_times[0].append(duration)
opt2_latencies[0].append(latency)
else:
opt2_execution_times[1].append(duration)
opt2_latencies[1].append(latency)
if data['Meta']['UsingExistingRestContainer']:
num_using_existing_rest_container += 1
opt3_execution_times[0].append(duration)
opt3_latencies[0].append(latency)
else:
opt3_execution_times[1].append(duration)
opt3_latencies[1].append(latency)
executions_per_node[node_id][function_name] = executions_per_node[node_id].get(function_name, 0) + 1
if DETAIL_LEVEL >= 1:
print('Total:', num_total)
for node_id, d in enumerate(executions_per_node):
print('Node %d | total: %d | avg: %.1f/s | %s' % (
node_id,
sum(d.values()),
sum(d.values()) / max_timeslot,
d
))
print('------------------------Locality------------------------')
avg_num_df = []
per_time = [{} for _ in range(0, max_timeslot)]
for node_id, data in enumerate(ret):
# Sample format of `data`:
# [{'W7': 1, 'T2': 1, 'W4': 2, 'W5': 2, 'D3': 1}, ...]
arr = [len(d.keys()) for d in data]
# `arr` means number of distinct functions of the node where index is timeslot
# Sample format of `arr`:
# [1, 2, 1, 2, 2, 3, 1, ...]
avg_num_df.append(avg(arr))
for timeslot, dic in enumerate(data):
per_time[timeslot][node_id] = len(dic.keys())
print('# of distinct functions for each node: %.1f (stddev.: %.1f)' % (
avg(avg_num_df),
stdd(avg_num_df),
))
if DETAIL_LEVEL >= 2:
for timeslot, row in enumerate(per_time):
if timeslot > 300: continue
print('(%d, %.1f)' % (timeslot, avg(row.values())), end=' ')
print('\n')
print('\n------------------------Imbalance------------------------')
avg_executions = []
per_time = [{} for _ in range(0, max_timeslot)]
for node_id, data in enumerate(ret):
arr = [sum(d.values()) for d in data]
avg_executions.append(avg(arr))
for timeslot, dic in enumerate(data):
per_time[timeslot][node_id] = sum(dic.values())
print('CV: %.2f (sttdev.: %.2f, avg: %.2f)' % (
stdd(avg_executions) / avg(avg_executions),
stdd(avg_executions),
avg(avg_executions),
))
if DETAIL_LEVEL >= 2:
print('CV:')
for timeslot, row in enumerate(per_time):
if timeslot > 300 or timeslot < 10: continue
v = row.values()
cv = stdd(v) / avg(v) if avg(v) != 0 else 0
print('(%d, %.2f)' % (timeslot, cv), end=' ')
print('')
print('\n-------------------- Cache hits --------------------')
print(' | Hit | Miss | % | H.E.Time | M.E.Time |')
def print_row(*cols):
print('%s | %s | %s | %s | %sms | %sms |' % (
cols[0].ljust(26),
str(cols[1]).rjust(5),
str(cols[2]).rjust(5),
str(cols[3]).rjust(3),
str(round(cols[4])).rjust(6),
str(round(cols[5])).rjust(6),
))
print_row(
'ImageReuse',
num_image_hit,
num_total - num_image_hit,
percentile(num_image_hit, num_total),
avg(opt1_execution_times[0]),
avg(opt1_execution_times[1]),
)
print_row(
'UsingPooledContainer',
num_using_pooled_container,
num_total - num_using_pooled_container,
percentile(num_using_pooled_container, num_total),
avg(opt2_execution_times[0]),
avg(opt2_execution_times[1]),
)
print_row(
'UsingExistingRestContainer',
num_using_existing_rest_container,
num_total - num_using_existing_rest_container,
percentile(num_using_existing_rest_container, num_total),
avg(opt3_execution_times[0]),
avg(opt3_execution_times[1]),
)
print('')
print('-------------------- Exec time / latency --------------------')
print('avg exec time: %dms\navg latency: %dms' % (
avg(durations),
avg(latencies),
))
print('')
if DETAIL_LEVEL >= 1:
print('Total executions:', num_total)
tmp = sorted(durations_per_functions.items(), key=lambda e: len(e[1]), reverse=True)
keys = [e[0] for e in tmp]
for fname in keys:
cnt = len(durations_per_functions[fname])
dur = avg(durations_per_functions[fname])
latency = avg(latencies_per_functions[fname])
print('%s: %dms (n=%d)(internal: %dms, latency: %dms)' % (
fname,
dur,
cnt,
dur - latency,
latency,
))
print('avg algorithm latency: %.1fμs' % (avg(algorithm_latencies) * 1000))