Last active
November 24, 2016 01:16
-
-
Save netj/28195e3d94ee922e22aabdebca04178c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# simple network I/O bandwidth test with ssh and pv | |
# Author: Jaeho Shin <[email protected]> | |
# 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