-
Notifications
You must be signed in to change notification settings - Fork 3
/
experiment_launcher.py
225 lines (184 loc) · 8.28 KB
/
experiment_launcher.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
import logging
from icecream import ic
import enoslib as en
import os
import datetime
import subprocess
import time
import sys
from rich.console import Console
from rich.progress import track
console = Console()
#Upload launch script to site frontend
def execute_ssh_command(ssh_command, login, site):
try:
# Execute the SSH command
result = subprocess.run(ssh_command, shell=True, capture_output=True, text=True)
# Check if the command was successful
if result.returncode == 0:
# Print the output
print(result.stdout)
else:
# Print the error message
print(result.stderr)
except subprocess.CalledProcessError as e:
print(f"Error occurred while executing SSH command: {e}")
#Get timestamp after end of experiment
def add_time(original_time, hours=0, minutes=0, seconds=0):
time_delta = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
new_time = original_time + time_delta
return new_time
def convert_seconds_to_time(seconds):
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return hours, minutes, seconds
def seconds_to_hh_mm_ss(seconds):
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
#Experiment node partition between Grid5000 machine
def node_partition(nb_cluster_machine, nb_builder, nb_validator, nb_regular):
partition = [[0, 0, 0] for i in range(nb_cluster_machine)]
index = 0
while nb_builder > 0 or nb_validator > 0 or nb_regular > 0:
if index == len(partition):
index = 0
if nb_builder > 0:
partition[index][0] += 1
nb_builder -= 1
elif nb_validator > 0:
partition[index][1] += 1
nb_validator -= 1
elif nb_regular > 0:
partition[index][2] += 1
nb_regular -= 1
index += 1
return partition
def main(output_dir):
#========== Parameters ==========
#Grid5000 parameters
USERNAME = "kpeeroo" #Grid5000 login
site = "lyon" #Grid5000 Site See: https://www.grid5000.fr/w/Status and https://www.grid5000.fr/w/Hardware
cluster = "taurus" #Gride5000 Cluster name See: https://www.grid5000.fr/w/Status and https://www.grid5000.fr/w/Hardware
job_name = "PANDAS_libp2p"
#Node launch script path
dir_path = os.path.dirname(os.path.realpath(__file__)) #Get current directory path
launch_script = dir_path +"/" + "run.sh"
#Experiment parameters
PARCEL_SIZE = 512
#Number of machine booked on the cluster
nb_cluster_machine = 3
#Number of nodes running for the experiment
nb_experiment_node = 3
nb_builder = 1
nb_validator = 1
nb_regular = nb_experiment_node - nb_builder - nb_validator
current_datetime = datetime.datetime.now()
current_datetime_string = current_datetime.strftime("%Y-%m-%d-%H:%M:%S")
experiment_name = f"PANDAS_libp2p_{nb_builder}b_{nb_validator}v_{nb_regular}r_{PARCEL_SIZE}p_{current_datetime_string}"
EXPERIMENT_DURATION_SECS = 60
WALLTIME_SECS = EXPERIMENT_DURATION_SECS + 60 # 60 seconds buffer
#Network parameters
delay = "10%"
rate = "1gbit"
loss = "0%"
symmetric=True
#========== Experiment nodes partition on cluster machines ==========
partition = node_partition(nb_cluster_machine, nb_builder, nb_validator, nb_regular)
#========== Create and validate Grid5000 and network emulation configurations ==========
#Log to Grid5000 and check connection
en.init_logging(level=logging.INFO)
en.check()
# network = en.G5kNetworkConf(type="prod", roles=["experiment_network"], site=site)
network = en.G5kNetworkConf(type="kavlan", roles=["experiment_network"], site=site)
job_walltime = seconds_to_hh_mm_ss(WALLTIME_SECS)
conf = (
en.G5kConf.from_settings(job_name=job_name, walltime=job_walltime)
.add_network_conf(network)
.add_machine(roles=["experiment"], cluster=cluster, nodes=nb_cluster_machine, primary_network=network) # Add experiment nodes
.finalize()
)
#Validate Grid5000 configuration
provider = en.G5k(conf)
roles, networks = provider.init()
roles = en.sync_info(roles, networks)
# #========== Grid5000 network emulation configuration ==========
# #network parameters
# netem = en.NetemHTB()
# (
# netem.add_constraints(
# src=roles["experiment"],
# dest=roles["experiment"],
# delay=delay,
# rate=rate,
# loss=loss,
# symmetric=symmetric,
# )
# )
# #Deploy network emulation
# netem.deploy()
# netem.validate()
#========== Deploy Experiment ==========
#Send launch script to Grid5000 site frontend
ssh_command = f'scp {launch_script} {USERNAME}@access.grid5000.fr:{site}'
execute_ssh_command(ssh_command, USERNAME, site)
i = 0
results = en.run_command("ip -o -4 addr show scope global | awk '!/^[0-9]+: lo:/ {print $4}' | cut -d '/' -f 1", roles=roles["experiment"][0])
builder_ip = results[0].payload["stdout"]
for x in roles["experiment"]:
with en.actions(roles=x, on_error_continue=True, background=True) as p:
# if x == roles["experiment"][0]:
# builder, validator, regular = partition[i]
# p.shell(f"/home/{USERNAME}/run.sh {experiment_name} {builder} {validator} {regular} {USERNAME} 127.0.0.1 {PARCEL_SIZE}")
# i += 1
# else:
builder, validator, regular = partition[i]
p.shell(f"/home/{USERNAME}/run.sh {experiment_name} {builder} {validator} {regular} {USERNAME} {builder_ip} {PARCEL_SIZE} {EXPERIMENT_DURATION_SECS} >> run_sh_output_{current_datetime_string}_{i}.txt 2>&1")
i += 1
start = datetime.datetime.now() #Timestamp grid5000 job start
start_formatted = start.strftime("%H:%M:%S")
console.print("Start: ", start_formatted, style="bold green")
console.print("Expected End: ", add_time(start, seconds=WALLTIME_SECS).strftime("%H:%M:%S"), style="bold green")
# for i in track(range(WALLTIME_SECS), description=f"Waiting for walltime ({WALLTIME_SECS} secs)..."):
# time.sleep(1)
"""
if output_dir != None:
1. Get all folders in remote results folder
2. Get all folders in local folder
3. Find the ones that are remote and not in local folder
4. Download them
5. Remove them from remote folder
results_dir = f"/results"
# Get all folders in remote results folder
remote_folders = f"ssh {login}@access.grid5000.fr ls {site}{results_dir}"
remote_folders = subprocess.run(remote_folders, shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8").split("\n")
remote_folders = [folder for folder in remote_folders if folder != ""]
# Get all folders in local folder
local_folders = [f for f in os.listdir(output_dir) if os.path.isdir(os.path.join(output_dir, f))]
# Find the ones that are remote and not in local folder
folders_to_download = [folder for folder in remote_folders if folder not in local_folders]
# Download them
for folder in folders_to_download:
remote_path = os.path.join(results_dir, folder)
local_path = os.path.join(output_dir, folder)
subprocess.run(f"scp -rC {login}@access.grid5000.fr:{site}{remote_path} {local_path}")
# Remove them from remote folder
for folder in folders_to_download:
remote_path = os.path.join(results_dir, folder)
subprocess.run(["ssh", f"{login}@access.grid5000.fr", f"rm -rf {site}{remote_path}"])
"""
#Release all Grid'5000 resources
# netem.destroy()
# provider.destroy()
if __name__ == "__main__":
# Check if argument is sent in and is a valid dir path
if len(sys.argv) > 1:
dir_path = sys.argv[1]
if not os.path.isdir(dir_path):
console.print(f"{dir_path} is an invalid directory path", style="bold red")
main(None)
else:
main(dir_path)
else:
main(None)