Skip to content

Instantly share code, notes, and snippets.

@vy
Created May 11, 2012 10:48
Show Gist options
  • Save vy/2658922 to your computer and use it in GitHub Desktop.
Save vy/2658922 to your computer and use it in GitHub Desktop.
Linux IP Alias Benchmark
#!/bin/bash
set -e
if [ $# -ne 3 ]; then
echo "Usage: $0 <ADDR_TMPL> <N_WORKERS> <TIMEOUT>"
exit 1
fi
ADDR_TMPL="$1"
N_WORKERS="$2"
TIMEOUT="$3"
start() {
(PIDS=();
for I in `seq 1 $N_WORKERS`; do
(iperf \
--format k \
--reportexclude CMSV \
--time $TIMEOUT \
--client \
$(printf $ADDR_TMPL $I) | \
grep "Kbits/sec" | \
sed -r 's/^.* ([0-9]+) Kbits\/sec/\1/g'; \
PIDS[$I]=$!) &
done;
wait ${PIDS[@]}) | \
awk 'BEGIN{s=0} {s+=$1} END{print s}'
exit 0
}
stop() {
exit 0
}
trap stop INT
start
reset
set terminal jpeg enhanced
set output "results.jpg"
set key left
set ylabel "Mbits/sec"
set xlabel "# of aliases"
set grid
plot 'results.dat' using 1:($2/1000.0) with points pointtype 7 title '', \
'' using 1:($2/1000.0) smooth csplines title ''
#!/bin/bash
set -e
if [ $# -ne 3 ]; then
echo "Usage: $0 <NAME_TMPL> <ADDR_TMPL> <N_WORKERS>"
exit 1
fi
NAME_TMPL="$1"
ADDR_TMPL="$2"
N_WORKERS="$3"
start() {
echo "Taking network interfaces up..."
for I in `seq 1 $N_WORKERS`; do
sudo ifconfig $(printf $NAME_TMPL $I) $(printf $ADDR_TMPL $I)
done
echo "Starting iperf servers..."
for I in `seq 1 $N_WORKERS`; do
iperf --server --bind $(printf $ADDR_TMPL $I) &
done
echo "Started."
}
stop() {
echo "Taking network interfaces down..."
for I in `seq $N_WORKERS -1 1`; do
sudo ifconfig $(printf $NAME_TMPL $I) down
done
echo "Stopped."
exit 0
}
trap stop INT
start && while /bin/true; do sleep 5m; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment