-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark
executable file
·99 lines (83 loc) · 2.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
function cleanup {
$(pkill -15 broker-node 2> /dev/null)
$(pkill -15 broker-pipe 2> /dev/null)
}
trap cleanup INT TERM EXIT
function launch_relay() {
listen=$1
peer=$2
echo "start relay ${listen} <-> ${peer}" 1>&2
broker-node -N "relay_${listen}" ${verbose:+'-v'} -l ${listen} -t '/bench/throughput' -m "relay" -p "[<tcp://[127.0.0.1]:${peer}>]" &
}
function launch_subscriber {
listen=$1
num_relays=$2
bytes=$3
echo "start subscriber at ${listen}" 1>&2
broker-pipe -l ${listen} -t '/bench/throughput' --mode="subscribe" --impl="blocking" --rate | awk -v n=$num_relays -v p=$payload '{ print n "," p "," $1 }' >> throughput.csv &
}
function launch_publisher {
peer=$1
bytes=$2
echo "start publisher connecting to ${peer}, sending ${bytes} bytes per message indefinitely" 1>&2
./generate ${bytes} | broker-pipe --peers="[\"127.0.0.1:${peer}\"]" -t '/bench/throughput' --mode="publish" --impl="blocking" &
}
function bench() {
num_relays=$1
bytes=$2
echo "relays: $num_relays, bytes: $bytes"
launch_subscriber $port $num_relays $bytes
sleep 1
((port++))
for node in $(seq 1 $num_relays); do
launch_relay $port $((port-1))
sleep 1
((port++))
done
launch_publisher $((port-1)) ${bytes}
sleep 15
cleanup
}
USAGE="usage: $0 [options] <min-num-relays> <max-num-relays>"
unset verbose
unset help_
append=false
port=4001
iterations=100
ret=0
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; ret=1;;
esac
done
shift $((OPTIND-1))
if [ "$help_" = true ] || [ "$#" -lt 2 ]; then
echo $USAGE
exit $ret;
fi
if ! which broker-node > /dev/null 2>&1; then
echo 'broker-node not found in $PATH'
exit 1
fi
if ! which broker-pipe > /dev/null 2>&1; then
echo 'broker-pipe not found in $PATH'
exit 1
fi
if [ "$append" = false ]; then
rm -f throughput.csv
echo "relays,payload,messages" > throughput.csv
fi
make generate
for relays in $(seq $1 $2); do
for payload in 0 1 10 100 1000 10000 100000 1000000 10000000; do
#for payload in 0 1 10 100; do
bench $relays $payload
done
done
exit $ret