-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexperiment-replication.py
executable file
·234 lines (193 loc) · 7.72 KB
/
experiment-replication.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
#!/usr/bin/env python3
import os
import random
import subprocess
import sys
import typing
class Experiment:
def __init__(
self,
function: str,
threads: int,
load_requests: int,
load_frequency: int,
delay_ms: int,
bandwidth_mbps: int,
delay_ms_client_edge: int,
bandwidth_mbps_client_edge: int,
delay_ms_edge_edge: int,
bandwidth_mbps_edge_edge: int,
deployment_mode: str,
timeout: int,
repeat: int,
results_dir: str,
output_dir: str,
):
self.function = function
self.threads = threads
self.load_requests = load_requests
self.load_frequency = load_frequency
self.delay_ms = delay_ms
self.bandwidth_mbps = bandwidth_mbps
self.delay_ms_client_edge = delay_ms_client_edge
self.bandwidth_mbps_client_edge = bandwidth_mbps_client_edge
self.delay_ms_edge_edge = delay_ms_edge_edge
self.bandwidth_mbps_edge_edge = bandwidth_mbps_edge_edge
self.deployment_mode = deployment_mode
self.timeout = timeout
self.repeat = repeat
self.results_file = os.path.join(
results_dir,
f"{function}-{threads}-{load_requests}-{load_frequency}-{delay_ms}-{bandwidth_mbps}-{delay_ms_client_edge}-{bandwidth_mbps_client_edge}-{delay_ms_edge_edge}-{bandwidth_mbps_edge_edge}-{deployment_mode}-{repeat}.csv",
)
self.output_file = os.path.join(
output_dir,
f"{function}-{threads}-{load_requests}-{load_frequency}-{delay_ms}-{bandwidth_mbps}-{delay_ms_client_edge}-{bandwidth_mbps_client_edge}-{delay_ms_edge_edge}-{bandwidth_mbps_edge_edge}-{deployment_mode}-{repeat}.txt",
)
def run(self) -> None:
# if the results file exists already, we can skip this experiment
if os.path.exists(self.results_file):
print(f"Skipping experiment: {self.results_file}")
return
print(f"Running experiment: {self.results_file}")
print(f"Output: {self.output_file}")
with open(self.output_file, "w") as f:
subprocess.run(
[
"./run-replication.sh",
self.function,
str(self.threads),
str(self.load_requests),
str(self.load_frequency),
self.results_file,
str(self.delay_ms),
str(self.bandwidth_mbps),
str(self.delay_ms_client_edge),
str(self.bandwidth_mbps_client_edge),
str(self.delay_ms_edge_edge),
str(self.bandwidth_mbps_edge_edge),
self.deployment_mode,
str(self.timeout),
],
stdout=f,
stderr=f,
)
print(f"Finished experiment: {self.results_file}")
# give stats
# print results
try:
with open(self.results_file, "r") as f:
lines = f.readlines()
# remove header
lines = [line.strip() for line in lines[1:]]
# get mean, median, 95th, 99th
stalenesses = [
float(line.split(",")[3]) for line in lines if line[0] == "r"
]
stalenesses.sort()
mean = sum(stalenesses) / len(stalenesses)
median = stalenesses[len(stalenesses) // 2]
p95 = stalenesses[int(len(stalenesses) * 0.95)]
p99 = stalenesses[int(len(stalenesses) * 0.99)]
print(f"mean stalenesses: {mean:.3f}s")
print(f"median stalenesses: {median:.3f}s")
print(f"95th stalenesses: {p95:.3f}s")
print(f"99th stalenesses: {p99:.3f}s")
read_times = [
(float(line.split(",")[2]) - float(line.split(",")[1]))
for line in lines
if line[0] == "r"
]
read_times.sort()
mean = sum(read_times) / len(read_times)
median = read_times[len(read_times) // 2]
p95 = read_times[int(len(read_times) * 0.95)]
p99 = read_times[int(len(read_times) * 0.99)]
print(f"mean read times: {mean:.3f}s")
print(f"median read times: {median:.3f}s")
print(f"95th read times: {p95:.3f}s")
print(f"99th read times: {p99:.3f}s")
write_times = [
(float(line.split(",")[2]) - float(line.split(",")[1]))
for line in lines
if line[0] == "w"
]
write_times.sort()
mean = sum(write_times) / len(write_times)
median = write_times[len(write_times) // 2]
p95 = write_times[int(len(write_times) * 0.95)]
p99 = write_times[int(len(write_times) * 0.99)]
print(f"mean write times: {mean:.3f}s")
print(f"median write times: {median:.3f}s")
print(f"95th write times: {p95:.3f}s")
print(f"99th write times: {p99:.3f}s")
except Exception as e:
print(e)
print("Failed to get stats")
if __name__ == "__main__":
# functions and inputs
function = "6_replication"
# experiment length about 5 minutes?
experiment_length = 5 * 60
# load frequency about 10 requests per second?
load_frequency = 10
# number of requests
num_requests = experiment_length * load_frequency
threads = 4
delay_ms = 25 # ms, one-way
bandwidth_mbps = 100 # Mbps
delay_ms_client_edge = 1 # ms, one-way
bandwidth_mbps_client_edge = 10 # Mbps
delay_ms_edge_edge = 10 # ms, one-way
bandwidth_mbps_edge_edge = 100 # Mbps
deployment_modes = ["edge", "cloud", "p2p"]
repeats = [1, 2, 3]
results_dir = "results/results-replication"
os.makedirs(results_dir, exist_ok=True)
output_dir = "output/output-replication"
os.makedirs(output_dir, exist_ok=True)
preparation_file = os.path.join(output_dir, "preparation.txt")
experiments = []
for m in deployment_modes:
for r in repeats:
e = Experiment(
function=function,
threads=threads,
load_requests=num_requests,
load_frequency=load_frequency,
delay_ms=delay_ms,
bandwidth_mbps=bandwidth_mbps,
delay_ms_client_edge=delay_ms_client_edge,
bandwidth_mbps_client_edge=bandwidth_mbps_client_edge,
delay_ms_edge_edge=delay_ms_edge_edge,
bandwidth_mbps_edge_edge=bandwidth_mbps_edge_edge,
deployment_mode=m,
timeout=experiment_length + 30,
repeat=r,
results_dir=results_dir,
output_dir=output_dir,
)
experiments.append(e)
# randomize the order of experiments
random.seed(0)
random.shuffle(experiments)
# prepare
with open(preparation_file, "w") as of:
print("Preparing...")
print(f"Output: {preparation_file}")
subprocess.run(["./prep-replication.sh"], stdout=of, stderr=of)
try:
for e in experiments:
e.run()
except Exception as e:
print(e)
except KeyboardInterrupt:
print("KeyboardInterrupt")
with open(preparation_file, "a") as of:
print("Cleaning up...")
print(f"Output: {preparation_file}")
subprocess.run(
["terraform", "destroy", "-auto-approve", "-var=second_edge_host=true"],
stdout=of,
stderr=of,
)