Skip to content

Instantly share code, notes, and snippets.

@netj
Last active November 24, 2016 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netj/28195e3d94ee922e22aabdebca04178c to your computer and use it in GitHub Desktop.
Save netj/28195e3d94ee922e22aabdebca04178c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# simple network I/O bandwidth test with ssh and pv
# Author: Jaeho Shin <netj@cs.stanford.edu>
# Created: circa 2013
host=${1:?ssh-able host name}; shift
maxbytes=${1:-$((2 ** 29))}; shift
bs=${1:-$((2 ** 16))}; shift
# rest are ssh options
set -- ssh -S none -o Compression=no -o ControlMaster=no "$@" $host
# disable pv unless stderr is a terminal and not inside Jupyter Notebook
[[ -t 2 && -z "${JPY_PARENT_PID:-}" ]] || pv() { cat; }
normalizeSize() {
{
echo "k=2^10;m=2^20;g=2^30;t=2^40;"
tr A-Z a-z | sed 's/[kmgt]/* &/g'
} <<<"$1" | bc
}
bs=$(normalizeSize "$bs")
maxbytes=$(normalizeSize "$maxbytes")
echo "## Bandwidth in-bound from $host"; {
"$@" \
dd if=/dev/zero bs=$bs count=$(($maxbytes / $bs)) |
pv --average-rate --bytes --progress --timer --size $maxbytes --buffer-size $bs |
dd of=/dev/null
}
echo
echo "## Bandwidth out-bound to $host"; {
dd if=/dev/zero bs=$bs count=$(($maxbytes / $bs)) |
pv --average-rate --bytes --progress --timer --size $maxbytes --buffer-size $bs |
"$@" \
dd of=/dev/null
}
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment