-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark
executable file
·81 lines (69 loc) · 1.8 KB
/
benchmark
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
#!/usr/bin/env bash
function launch_ping() {
peer=$1
num_relays=$2
for payload in 0 1 10 100 1000 10000 100000 1000000 10000000 100000000; do
echo "start ping for $num_relays relays with payload $payload connecting to peer $peer"
out=$(broker-node ${verbose:+'-v'} -N "ping" -p "[<tcp://[::1]:$peer>]" -t foobar -m "'ping'" -n ${iterations} -s $payload)
while read -r line; do
echo "$num_relays,$payload,$line" >> latency.csv
done <<< "$out"
done
}
function launch_relay() {
listen=$1
peer=$2
echo "start relay ${listen} <-> ${peer}" 1>&2
broker-node -N "relay_${listen}" ${verbose:+'-v'} -l ${listen} -t foobar -m "'relay'" -p "[<tcp://[::1]:${peer}>]" &
}
function launch_pong() {
listen=$1
echo "start pong at port ${listen}" 1>&2
broker-node -N "pong" ${verbose:+'-v'} -l ${listen} -t foobar -m "'pong'" & 2> pong.log
}
function run_test() {
num_relays=$1
echo "----------------- $num_relays relay(s) -----------------"
launch_pong $port
((port++))
for node in $(seq 1 $num_relays); do
launch_relay $port $((port-1))
((port++))
done
launch_ping $((port-1)) $num_relays
# cleanup
killall broker-node
}
USAGE="usage: $0 [options] <min-num-relays> <max-num-relays>"
unset verbose
unset help_
append=false
port=4001
iterations=100
while getopts "n:p:ahv" flag; do
case "$flag" in
n) iterations=$OPTARG;;
p) port=$OPTARG;;
a) append=true;;
h) help_=true;;
v) verbose=true;;
\?) help_=true;;
esac
done
shift $((OPTIND-1))
if [ "$help_" = true ] || [ "$#" -lt 2 ]; then
echo $USAGE
exit 1
fi
if ! which broker-node > /dev/null 2>&1; then
echo 'broker-node not found in $PATH'
exit 1
fi
if [ "$append" = false ]; then
rm -f latency.csv
echo "relays,payload,rtt" > latency.csv
fi
for i in $(seq $1 $2); do
run_test $i
done
exit 0