-
Notifications
You must be signed in to change notification settings - Fork 5
/
multi-iperf.sh
executable file
·179 lines (152 loc) · 4.89 KB
/
multi-iperf.sh
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
#!/bin/bash
#
# Title: multi-iperf.sh
# Description: A helper script for making parallel iperf sessions.
# Author: Rok Strnisa <[email protected]>
# Source: https://github.com/perf101/scripts
# FAIL IF ANY COMMAND FAILS
set -e
# DEFAULTS
aggregate=false
b_size=
out=
simple=false
threads=1
duration=5
verbose=false
declare -a vmips
vms=
w_size=
xentop_host=
# USAGE
basename=`basename ${0}`
usage_prefix="Usage: ${basename} "
indent=`printf "%${#usage_prefix}s" " "`
usage="${usage_prefix}[-h|--help] [-i <IP,IP,..>] [-n <INT>] [-t <INT>]
${indent}[-o <PATH>|--output <PATH>] [-P <INT>] [-x <HOST>]
${indent}[-b <INT>] [-w <INT>] [-f] [-v] [-a]
-a
Output aggregate network throughput (in Mbps) to standard output.
-b <INT>
Iperf buffer size in KB to use. The receiving side should probably use
the same buffer size. Default depends on your Iperf implementation and
your system.
-f
Fix Iperf buffer size (-b) and window size (-w) to 256KB. Recommended
when sending traffic to Windows VMs. (Iperfs on those VMs should
probably use the same buffer and window size.)
-h, --help
Show usage instructions.
-i <IP,IP,..>
A comma-separated list of VM IPs. Used for establishing Iperf sessions
with the VMs. The number of IPs must be equal or greater than the number
specified for -n. No default.
-n <INT>
Create concurrent Iperf sessions with <INT> VMs. Must be smaller than or
equal to the number of IPs specified in -i. Default is the number of IPs
specified with -i.
-o <PATH>, --output <PATH>
Save results (in Mbps) into the file at <PATH> instead of outputting
them to standard output.
-P <INT>
Create <INT> Iperf threads per Iperf session. Default is ${threads}.
-s
Simple output. Only outputs the aggregate number (in Mbps). Implies -a.
-t <INT>
Set the test to last <INT> seconds. Default is ${duration}. Recommended
is 60 or more.
-v
Verbose. At the moment, this only shows the final Iperf configuration.
-w <INT>
Iperf window size in KB to use. The receiving side should probably use
the same window size. Default depends on your Iperf implementation and
your system.
-x <HOST>
Specify a <HOST> (any address reachable via SSH without user interaction)
for which to track CPU usage via xentop. The resolution is one xentop
snapshot per second. The output is stored in _xentop, or <PATH>_xentop
where <PATH> is the argument for -o.
"
# OVERRIDE DEFAULTS WITH ARGUMENTS
while [ -n "${1}" ]; do
case ${1} in
-a) aggregate=true;;
-b) shift; b_size=${1};;
-f) b_size=256; w_size=256;;
-h | --help) echo "${usage}" | less -FX; exit;;
-i) shift; IFS=',' read -ra vmips <<< "${1}";;
-n) shift; vms=${1};;
-o | --output) shift; out=${1};;
-P) shift; threads=${1};;
-s) aggregate=true; simple=true;;
-t) shift; duration=${1};;
-v) verbose=true;;
-w) shift; w_size=${1};;
-x) shift; xentop_host=${1};;
*) echo "${usage}" | less -FX; exit 1
esac
shift
done
# FAIL IF A VARIABLE IS NOT SET
set -u
# VARIABLE CONSISTENCY CHECK AND POSTPROCESSING
if [ -z "${vms}" ]; then
vms=${#vmips[@]}
fi
if [ ${vms} -gt ${#vmips[@]} ]; then
echo "Error: # VMs (-n) is greater than # IPs (-VMIPs): ${vms} > ${#vmips[@]}."
echo "See usage instructions with: $0 -h"
exit 1
fi
if [ -n "${b_size}" ]; then
b_size=" -l ${b_size}K"
fi
if [ -n "${w_size}" ]; then
w_size=" -w ${w_size}K"
fi
xentop_out="${out}_xentop"
# START RECORDING XENTOP USAGE ON RECEIVER
if [ -n "${xentop_host}" ]; then
if ${verbose}; then echo "Starting xentop logging for ${xentop_host} .."; fi
ssh ${xentop_host} "xentop -b -d 1 -f" > "${xentop_out}" &
pid=${!}
if ${verbose}; then echo "Output file for xentop logging: ${xentop_out}"; fi
fi
# START PARALLEL IPERF SESSIONS
iperf_flags="${b_size}${w_size} -t ${duration} -P ${threads} -f m"
if ${verbose}; then echo "Using Iperf flags:${iperf_flags}"; fi
tmp=`mktemp`
declare -a pids
for i in `seq ${vms}`; do
vm_ip=${vmips[i-1]}
if ${verbose}; then echo "Connecting to ${vm_ip} .."; fi
iperf -c ${vm_ip} ${iperf_flags} \
| grep -v "SUM" \
| grep -o "[0-9.]\+ Mbits/sec" \
| awk -vIP=${vm_ip} '{print IP, $1}' \
>> ${tmp} &
pids[i]=$!
done
# WAIT FOR THE TESTS TO COMPLETE
wait ${pids[@]}
# STOP RECORDING XENTOP USAGE
if [ -n "${xentop_host}" ]; then
if ${verbose}; then echo "Stopping xentop logging for ${xentop_host} .."; fi
kill ${pid};
fi
# SORT INDIVIDUAL RESULTS
tmp2=`mktemp`
if ! ${simple}; then sort -o ${tmp2} ${tmp}; fi
# OUTPUT AGGREGATE THROUGHPUT TO STDOUT
if ${aggregate}; then
if ! ${simple}; then echo -n "AGGREGATE " >> ${tmp2}; fi
cat "${tmp}" | awk '{sum+=$2}END{print sum}' >> ${tmp2}
fi
# OUTPUT RESULTS
if [ -n "${out}" ]; then
cp ${tmp2} ${out}
else
cat ${tmp2}
fi
# REMOVE TEMPORARY FILES
rm -f ${tmp} ${tmp2}