Skip to content

Instantly share code, notes, and snippets.

@drewr
Created December 13, 2011 23:47
Show Gist options
  • Save drewr/1474513 to your computer and use it in GitHub Desktop.
Save drewr/1474513 to your computer and use it in GitHub Desktop.
parallel httperf
#!/bin/zsh
prog=$0
die() {
if [[ ! -z $1 ]]; then
print $1
fi
exit 1
}
if [[ "$#" -lt 2 ]]; then
print "usage: $prog REQS HOST:PORT [WORKER ...]"
print
print " REQS: File of httperf-compatible inputs. '-' if stdin."
print " HOST: The target HTTP server to test."
print " WORKER: Optional slave(s) that will issue the requests. If none is"
print " supplied, requests will come from localhost."
print
die "fatal: not enough args"
fi
NSESS=${NSESS:-5}
NDELAY=${NDELAY:-0}
prefix=$(basename $prog)
id=${prefix}-$(date +%Y%m%d%H%M%S.$$)
[[ ! -d $id ]] && mkdir $id
wdir=$(readlink -n -m $id)
reqs=$1; shift
target=(${(s_:_)1}); shift
orig=${wdir}/req-orig
workers=(${*:-localhost})
reqn=$(cat $reqs | tee $orig | wc -l | awk '{print $1}')
reqs=$orig
w=()
for h in $workers; do
if ssh $h bin/httperf --help \>/dev/null 2\>\&1; then
w+=($h)
else
print $h: no working httperf
fi
done
workers=($w)
splitfact=$(( $reqn / $#workers ))
hosts=hosts
pad=08
workpre=work-
if [[ $#target -gt 1 ]]; then
tarhost=$target[1]
tarport=$target[2]
else
tarhost=${target}
tarport=80
fi
print $id $reqn requests via $#workers workers '-->' $tarhost:$tarport
(
cd $wdir
split \
--suffix-length=$pad \
--numeric-suffixes \
--lines=$splitfact \
$reqs \
$workpre
i=0
for h in $workers; do
print $h >>hosts
f=${workpre}$(printf "%${pad}d" $i)
cat $f | ssh $h cat \>/tmp/${id}.wsesslog
i=$((i+1))
done
if [[ -f $hosts ]]; then
parallel-ssh \
-h $hosts \
-o req-out \
-e req-err \
\$HOME/bin/httperf --hog \
--server=${tarhost} --port=${tarport} \
--wsesslog=${NSESS},${NDELAY},/tmp/${id}.wsesslog >/dev/null
cd req-out
fgrep req/s *
else
print warn: no workers
fi
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment