Last active
August 29, 2015 14:07
-
-
Save andsens/573186933e80a74462bb to your computer and use it in GitHub Desktop.
Measure network throughput between two machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Idea snatched from http://kb.sp.parallels.com/en/115348 | |
# Command for quick installation: | |
# url='https://gist.githubusercontent.com/andsens/573186933e80a74462bb/raw/throughput.sh'; curl -so throughput.sh $url || wget --quiet -O throughput.sh $url; chmod +x throughput.sh | |
server() { | |
type pv > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
while true; do | |
nc -l 1122 | pv --rate > /dev/null | |
printf "\n" | |
done | |
else | |
while true; do | |
nc -l 1122 > /dev/null | |
printf "\n" | |
done | |
fi | |
} | |
client() { | |
[ -z $1 ] && usage | |
local host=$1 | |
# In MB | |
if [ -z $2 ]; then | |
local size=128 | |
else | |
local size=$2 | |
fi | |
# Check if we are dealing with the BSD or Linux version | |
# BSD version uses capital letters while Linux uses small ones. | |
dd if=/dev/zero of=/dev/null count=0 bs=1M > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
size=${size}M | |
else | |
size=${size}m | |
fi | |
dd if=/dev/zero bs=${size} count=1 | nc $host 1122 | |
} | |
usage() { | |
printf "%s" "Usage: | |
throughput.sh server | |
throughput.sh client <host> [<size>] | |
" | |
exit 64 # E_USAGE | |
} | |
[ -z $1 ] && usage | |
mode=$1 | |
if [ $mode = 'server' ]; then | |
server | |
fi | |
if [ $mode = 'client' ]; then | |
client "$2" "$3" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment