-
Notifications
You must be signed in to change notification settings - Fork 0
/
lasp_throughput_plot.sh
executable file
·366 lines (315 loc) · 11.1 KB
/
lasp_throughput_plot.sh
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/usr/bin/env escript
-author("Vitor Enes Duarte <[email protected]>").
main(_) ->
ValidDirectories = ordsets:from_list(["throughput", "divergence"]),
%% Filter out invalid directories
Simulations0 = only_dirs(root_log_dir()),
Simulations1 = lists:filter(
fun(Simulation) ->
ordsets:is_element(Simulation, ValidDirectories)
end,
Simulations0
),
%% Generate plots
lists:foreach(
fun(Simulation) ->
SimulationDir = root_log_dir() ++ "/" ++ Simulation,
LocalAndDCOS = only_dirs(SimulationDir),
lists:foreach(
fun(Dir) ->
Path = SimulationDir ++ "/" ++ Dir,
EvalIds = only_dirs(Path),
generate_plots(Simulation ++ "/" ++ Dir, EvalIds)
end,
LocalAndDCOS
)
end,
Simulations1
).
%% @doc Generate plots.
generate_plots(Simulation, EvalIds) ->
Map = lists:foldl(
fun(EvalId, Acc) ->
Tokens = string:tokens(EvalId, "_"),
IdMaxIndex = length(Tokens) -6,
EventIntervalIndex = length(Tokens) - 5,
MaxEventsIndex = length(Tokens) - 4,
BlockingSyncIndex = length(Tokens) - 3,
StateIntervalIndex = length(Tokens) - 2,
ClientNumberIndex = length(Tokens) - 1,
PartitionProbabilityIndex = length(Tokens),
EventInterval = lists:nth(EventIntervalIndex, Tokens),
MaxEvents = lists:nth(MaxEventsIndex, Tokens),
BlockingSync = lists:nth(BlockingSyncIndex, Tokens),
StateInterval = lists:nth(StateIntervalIndex, Tokens),
ClientNumber = list_to_integer(lists:nth(ClientNumberIndex, Tokens)),
_MaxEvents = lists:nth(MaxEventsIndex, Tokens),
_BlockingSync = lists:nth(BlockingSyncIndex, Tokens),
_StateInterval = lists:nth(StateIntervalIndex, Tokens),
_PartitionProbability = lists:nth(PartitionProbabilityIndex, Tokens),
_HeavyClients = lists:nth(1, Tokens) == "code",
Id = string:join(lists:sublist(Tokens, IdMaxIndex), "_"),
io:format("Analysing ~p~n", [EvalId]),
EvalIdDir = root_log_dir() ++ "/" ++ Simulation ++ "/" ++ EvalId,
EvalTimestamps = only_dirs(EvalIdDir),
T = lists:foldl(
fun(EvalTimestamp, ToAverage0) ->
EvalDir = EvalIdDir ++ "/" ++ EvalTimestamp,
Tuple = get_throughput_and_latency(EvalDir, EventInterval),
orddict:store(
EvalTimestamp,
Tuple,
ToAverage0
)
end,
orddict:new(),
EvalTimestamps
),
Tuple = average_throughput_and_latency(T),
MasterKey = {list_to_integer(MaxEvents),
list_to_atom(BlockingSync),
list_to_integer(StateInterval)},
PerIds0 = case orddict:find(MasterKey, Acc) of
{ok, PerIds} ->
PerIds;
error ->
orddict:new()
end,
PerClients0 = case orddict:find(Id, PerIds0) of
{ok, CPC} ->
CPC;
error ->
orddict:new()
end,
PerClients1 = orddict:store(ClientNumber, Tuple, PerClients0),
PerIds1 = orddict:store(Id, PerClients1, PerIds0),
orddict:store(MasterKey, PerIds1, Acc)
end,
orddict:new(),
EvalIds
),
io:format("~p~n", [Map]),
PlotDir = root_plot_dir() ++ "/" ++ Simulation ++ "/",
filelib:ensure_dir(PlotDir),
OutputFile = output_file(PlotDir, "throughput"),
{InputFiles, Titles} = lists:foldl(
fun({{MaxEvents, BlockingSync, StateInterval}=K, PerId}, {InputFiles0, Titles0}) ->
lists:foldl(
fun({Id, PerClient}, {InputFiles1, Titles1}) ->
Title = get_title(Id, K),
InputFile = PlotDir ++ Id ++ "_"
++ integer_to_list(MaxEvents) ++ "_"
++ atom_to_list(BlockingSync) ++ "_"
++ integer_to_list(StateInterval),
%% truncate file
write_to_file(InputFile, ""),
lists:foreach(
fun({ClientNumber, {T, L}}) ->
Line = float_to_list(T) ++ ","
++ float_to_list(L) ++ ","
++ integer_to_list(ClientNumber) ++ "\n",
append_to_file(InputFile, Line)
end,
PerClient
),
{[InputFile | InputFiles1], [Title | Titles1]}
end,
{InputFiles0, Titles0},
PerId
)
end,
{[], []},
Map
),
Result = run_gnuplot(InputFiles, Titles, OutputFile),
io:format("Generating transmission plot ~p. Output: ~p~n~n", [OutputFile, Result]).
%% @private
get_title(_Id, K) ->
get_title(K).
get_title("client_server_state_based_gcounter") -> "gcounter";
get_title("client_server_state_based_gset") -> "gset";
get_title("client_server_state_based_boolean") -> "boolean";
get_title("client_server_state_based_twopset") -> "add-only twopset";
get_title("client_server_state_based_awset_ps") -> "add-only provenance";
get_title({_, true, _}) -> "blocking";
get_title({_, false, Interval}) -> integer_to_list(Interval).
%% @private
root_log_dir() ->
"logs".
%% @private
root_plot_dir() ->
"plots".
%% @private
gnuplot_file() ->
"throughput.gnuplot".
%% @private
output_file(PlotDir, Name) ->
PlotDir ++ Name ++ ".pdf".
%% @private
only_dirs(Dir) ->
{ok, DirFiles} = file:list_dir(Dir),
%% Ignore files
lists:filter(
fun(Elem) ->
filelib:is_dir(Dir ++ "/" ++ Elem)
end,
DirFiles
).
%% @private
only_csv_files(LogDir) ->
{ok, LogFiles} = file:list_dir(LogDir),
%% Ignore not csv files
lists:filter(
fun(Elem) ->
case re:run(Elem, ".*.csv$") of
{match, _} ->
true;
nomatch ->
false
end
end,
LogFiles
).
%% @private
get_throughput_and_latency(EvalDir, EventInterval) ->
LogFiles = only_csv_files(EvalDir),
{Count, T, L} = lists:foldl(
fun(File, {CAcc, TAcc, LAcc}=Acc) ->
FilePath = EvalDir ++ "/" ++ File,
{Ignore, T0, L0} = get_single_throughput_and_latency(FilePath, EventInterval),
case Ignore of
true ->
Acc;
false ->
{CAcc + 1, TAcc + T0, LAcc + L0}
end
end,
{0, 0, 0},
LogFiles
),
%% average latency for this run
{T, L / Count}.
%% @private
get_single_throughput_and_latency(FilePath, EventInterval) ->
%% Open log file
{ok, FileDescriptor} = file:open(FilePath, [read]),
%io:format("Processing file: ~p~n", [FilePath]),
%% Ignore the first line
[_ | Lines] = read_lines(FilePath, FileDescriptor),
{Ignore, BatchLines} = lists:foldl(
fun(Line, {Ignore0, BatchLines0}=Acc) ->
[Type0, _Time0, BatchLine] = string:tokens(Line, ";\n"),
case list_to_atom(Type0) of
experiment_started ->
%% Ignore server logs
{true, BatchLines0};
batch ->
{Ignore0, BatchLines0 ++ [BatchLine]};
_ ->
Acc
end
end,
{false, []},
Lines
),
{Start, End, TotalOps, BatchNumber, BatchLatency} = lists:foldl(
fun(Line, {Start0, _End0, TotalOps0, BatchNumber0, BatchLatency0}) ->
[BatchStartMs, BatchEndMs, Ops, Ms] = string:tokens(Line, ","),
Start1 = case Start0 of
undefined ->
%% if not defined, use the first batch
%% start time
list_to_integer(BatchStartMs);
_ ->
Start0
end,
BatchSize = list_to_integer(Ops),
TotalBatchTime = list_to_integer(Ms),
Latency = (TotalBatchTime - ((BatchSize - 1) * list_to_integer(EventInterval))) / BatchSize,
{
Start1,
list_to_integer(BatchEndMs),
TotalOps0 + BatchSize,
BatchNumber0 + 1,
BatchLatency0 + Latency
}
end,
{undefined, undefined, 0, 0, 0},
BatchLines
),
case Ignore of
true ->
{true, 0, 0};
false ->
%io:format("TotalOps: ~p End: ~p, Start: ~p~n", [TotalOps, End, Start]),
Diff = End - Start,
T = TotalOps / (Diff / 1000),
L = (BatchLatency / 1000) / BatchNumber,
{Ignore, T, L}
end.
%% @private
read_lines(FilePath, FileDescriptor) ->
case io:get_line(FileDescriptor, '') of
eof ->
[];
{error, Error} ->
lager:warning("Error while reading line from file ~p. Error: ~p", [FilePath, Error]),
[];
Line ->
[Line | read_lines(FilePath, FileDescriptor)]
end.
%% @private
write_to_file(InputFile, Line) ->
file:write_file(InputFile, Line, [write]).
%% @private
append_to_file(InputFile, Line) ->
file:write_file(InputFile, Line, [append]).
%% @doc Average all executions
average_throughput_and_latency(ToAverage) ->
{NumberOfExecutions, TSum, _TList, LSum} = orddict:fold(
fun(_Timestamp, {TSec, LSec}, {CountAcc, TAcc, TAccList, LAcc}) ->
{CountAcc + 1, TAcc + TSec, TAccList ++ [TSec], LAcc + LSec}
end,
{0, 0, [], 0},
ToAverage
),
%io:format("[~p] ~p~n", [length(TList), TList]),
{TSum / NumberOfExecutions, LSum / NumberOfExecutions}.
%% @private
run_gnuplot(InputFiles, Titles, OutputFile) ->
Bin = case os:getenv("MESOS_TASK_ID", "false") of
"false" ->
"gnuplot";
_ ->
"/usr/bin/gnuplot"
end,
Command = Bin ++ " -e \""
++ "outputname='" ++ OutputFile ++ "'; "
++ "inputnames='" ++ join_filenames(InputFiles) ++ "'; "
++ "titles='" ++ join_titles(Titles) ++ "'\" " ++ gnuplot_file(),
io:format("~p~n~n", [Command]),
os:cmd(Command).
%% @private
join_filenames(InputFiles) ->
Line = lists:foldl(
fun(Elem, Acc) ->
Acc ++ Elem
++ " "
end,
"",
InputFiles
),
string:strip(Line).
%% @private
join_titles(Titles) ->
Line = lists:foldl(
fun(Elem, Acc) ->
% "*.gnuplot" does not support titles with spaces
% But it converts all the "_" in the titles to " "
Acc ++ re:replace(Elem, " ", "_", [global, {return, list}])
++ " "
end,
"",
Titles
),
string:strip(Line).