This repository has been archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
olympics.py
executable file
·272 lines (235 loc) · 8.31 KB
/
olympics.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
#!/usr/bin/env python3
import argparse
import os
import signal
import subprocess
import time
payloads_and_rates_wifi = [
[100, 500],
[200, 500],
[400, 500],
[1000, 500],
[2000, 500],
[4000, 100],
[10000, 100],
[20000, 100],
[40000, 50],
[100000, 10],
[200000, 10],
[400000, 5],
[1000000, 2],
[2000000, 1],
[4000000, 1],
[10000000, 1]
]
'''
payloads_and_rates = [
[1, 500],
[10, 500],
[20, 500],
[40, 500],
[100, 500],
[200, 500],
[400, 500],
[1000, 500],
[2000, 500],
[4000, 500],
[10000, 100],
[20000, 100],
[40000, 100],
[100000, 100],
[200000, 100],
[400000, 100],
[1000000, 30],
[2000000, 30],
[4000000, 30],
[10000000, 10],
[20000000, 10],
[40000000, 5],
]
'''
payloads_and_rates = payloads_and_rates_wifi
def run_ros2_pubsub(rmw, message_count, blob_size, rate, pub_host, sub_host):
print(f'launching echo process on [{pub_host}]')
echo_process = subprocess.Popen(
[
'ssh',
'-t',
sub_host,
f'/bin/bash -c "export RMW_IMPLEMENTATION={rmw} && . $HOME/middleware_olympics/build/ros2/install/setup.bash && ros2 run ros2_contestant echo"'],
preexec_fn=os.setsid,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
time.sleep(1)
# send some bonus messages to cover the connection time
ping_message_count = message_count + 2 * int(rate)
print(f'launching ping process on [{sub_host}]')
ping_process = subprocess.Popen(
[
'ssh',
'-t',
pub_host,
f'/bin/bash -c "export RMW_IMPLEMENTATION={rmw} && . $HOME/middleware_olympics/build/ros2/install/setup.bash && ros2 run ros2_contestant ping --ros-args -p max_message_count:={ping_message_count} -p publish_rate:={rate:.2f} -p blob_size:={blob_size} -p startup_delay:=3.0"'],
preexec_fn=os.setsid,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
expected_time = 4 + message_count / rate
print(f'waiting {expected_time} seconds for completion...')
time.sleep(expected_time)
print(f'collecting output...')
ping_stdout, ping_stderr = ping_process.communicate()
stats = ping_stdout.split()
print(f'killing processes...')
try:
os.killpg(os.getpgid(echo_process.pid), signal.SIGINT)
echo_process.wait(timeout=1)
except ProcessLookupError:
pass
try:
os.killpg(os.getpgid(ping_process.pid), signal.SIGINT)
ping_process.wait(timeout=1)
except ProcessLookupError:
pass
try:
latency_avg = float(stats[0])
latency_min = float(stats[1])
latency_max = float(stats[2])
latency_skipped = int(stats[3])
except Exception as e:
print(f'error parsing output: {stats}')
print(e)
return (latency_avg, latency_min, latency_max, latency_skipped)
def run_ros1_pubsub(message_count, blob_size, rate, tcp_nodelay, roscore_host, pub_host, sub_host):
# print(f'run_ros1_pubsub({message_count}, {blob_size}, {rate})')
echo_process = subprocess.Popen(
[
'ssh',
'-t',
sub_host,
f'/bin/bash -c "export ROS_MASTER_URI=http://{roscore_host}:11311/ && . $HOME/middleware_olympics/build/ros1/devel/setup.bash && rosrun ros1_contestant echo _tcp_nodelay:={str(tcp_nodelay).lower()}"'],
preexec_fn=os.setsid,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
time.sleep(2)
# send more messages to cover the connection time
ping_message_count = message_count + 5 * int(rate)
ping_process = subprocess.Popen(
[
'ssh',
'-t',
pub_host,
f'/bin/bash -c "export ROS_MASTER_URI=http://{roscore_host}:11311/ && . $HOME/middleware_olympics/build/ros1/devel/setup.bash && rosrun ros1_contestant ping _tcp_nodelay:={str(tcp_nodelay).lower()} _max_message_count:={ping_message_count} _publish_rate:={rate} _blob_size:={blob_size}"'],
preexec_fn=os.setsid,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
expected_time = 7 + message_count / rate
# print(f'waiting {expected_time} seconds for the event...')
time.sleep(expected_time)
ping_stdout, ping_stderr = ping_process.communicate()
stats = ping_stdout.split()
try:
os.killpg(os.getpgid(echo_process.pid), signal.SIGINT)
echo_process.wait(timeout=1)
except ProcessLookupError:
#print('echo process lookup error')
pass
try:
os.killpg(os.getpgid(ping_process.pid), signal.SIGINT)
ping_process.wait(timeout=1)
except ProcessLookupError:
#print('ping process lookup error')
pass
try:
latency_avg = float(stats[0])
latency_min = float(stats[1])
latency_max = float(stats[2])
latency_skipped = int(stats[3])
except Exception as e:
print(f'error parsing output: {stats}')
print(e)
return (latency_avg, latency_min, latency_max, latency_skipped)
def run_ros1(tcp_nodelay, pub_host, sub_host):
print('starting roscore...')
roscore_host = pub_host
roscore = subprocess.Popen(
['. $HOME/middleware_olympics/build/ros1/devel/setup.bash && roscore'],
shell=True,
executable='/bin/bash',
preexec_fn=os.setsid,
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
print('wait a bit for roscore to start up...')
time.sleep(5)
print('assuming roscore is alive now')
f = open(f'ros1_{tcp_nodelay}.csv', 'w')
for experiment in payloads_and_rates:
payload = experiment[0]
rate = experiment[1]
stats = run_ros1_pubsub(
rate * 10,
payload,
rate,
tcp_nodelay,
roscore_host,
pub_host,
sub_host)
latency_avg = stats[0]
latency_min = stats[1]
latency_max = stats[2]
skips = stats[3]
print(f'{payload} {rate} {latency_avg} {latency_min} {latency_max} {skips}')
f.write(f'{payload},{rate},{latency_avg},{latency_min},{latency_max},{skips}\n')
f.flush()
print('killing roscore...\n\n')
try:
os.killpg(os.getpgid(roscore.pid), signal.SIGINT)
roscore.wait(timeout=1)
except ProcessLookupError:
print('roscore ProcessLookupError')
def run_fastrtps(pub_host, sub_host):
f = open('fastrtps.csv', 'w')
for experiment in payloads_and_rates:
payload = experiment[0]
rate = experiment[1]
stats = run_ros2_pubsub('rmw_fastrtps_cpp', rate * 10, payload, rate, pub_host, sub_host)
latency_avg = stats[0]
latency_min = stats[1]
latency_max = stats[2]
skips = stats[3]
print(f'{payload} {rate} {latency_avg} {latency_min} {latency_max} {skips}')
f.write(f'{payload},{rate},{latency_avg},{latency_min},{latency_max},{skips}\n')
f.flush()
def run_cyclone(pub_host, sub_host):
f = open('cyclone.csv', 'w')
for experiment in payloads_and_rates:
payload = experiment[0]
rate = experiment[1]
stats = run_ros2_pubsub('rmw_cyclonedds_cpp', rate * 10, payload, rate, pub_host, sub_host)
latency_avg = stats[0]
latency_min = stats[1]
latency_max = stats[2]
skips = stats[3]
print(f'{payload} {rate} {latency_avg} {latency_min} {latency_max} {skips}')
f.write(f'{payload},{rate},{latency_avg},{latency_min},{latency_max},{skips}\n')
f.flush()
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument('contestant')
parser.add_argument('--pub_host', default='localhost')
parser.add_argument('--sub_host', default='localhost')
args = parser.parse_args()
if args.contestant == 'ros1':
run_ros1(False, args.pub_host, args.sub_host)
elif args.contestant == 'ros1_tcpnodelay':
run_ros1(True, args.pub_host, args.sub_host)
elif args.contestant == 'cyclone':
run_cyclone(args.pub_host, args.sub_host)
elif args.contestant == 'fastrtps':
run_fastrtps(args.pub_host, args.sub_host)
else:
print(f'unknown contestant: {args.contestant}')