Created
December 14, 2014 10:24
-
-
Save parkghost/fcf875b43878bc669b55 to your computer and use it in GitHub Desktop.
ab+.sh
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/bash | |
# ab+ | |
# | |
# os and network tuning | |
# ulimit -n 100000 | |
# sudo echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range | |
# sudo echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle | |
# sudo echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse | |
# sudo echo "10" > /proc/sys/net/ipv4/tcp_fin_timeout | |
# sudo echo "65535" > /proc/sys/net/core/somaxconn | |
# sudo echo "65535" > /proc/sys/net/ipv4/tcp_max_syn_backlog | |
AB_PATH=/usr/bin/ab | |
SS_PATH=/bin/ss | |
LOW_CONCURRENCY=100 | |
HIGH_CONCURRENCY=1000 | |
CONCURRENCY_STEP=100 | |
NUM_CALL=100 | |
HOST=$(echo "$*" | perl -ne '/http.*?:\/\/([^\/?:#]*)/; print $1') | |
PREFIX=$HOST$(date +"_%Y%m%d_%H%M") | |
OUTPUT_FILE=$PREFIX.csv | |
MAX_OPEN_FILES=$(ulimit -n) | |
trap "exit;" SIGINT SIGTERM | |
if [ "$MAX_OPEN_FILES" -le $HIGH_CONCURRENCY ]; then | |
echo "Warning: open file limit < HIGH_CONCURRENCY" | |
exit 1 | |
fi | |
echo "Starting benchmark" | |
mkdir -p temp/"$PREFIX" | |
echo "#$AB_PATH -c CONCURRENCY=($LOW_CONCURRENCY to $HIGH_CONCURRENCY step $CONCURRENCY_STEP) -n NUM=($NUM_CALL*CONCURRENCY) $*" | tee "$OUTPUT_FILE" | |
echo "#start time,concurrency,complete requests,failed requests,tps,min,mean,stddev,median,max,90%,95%,99%" | tee -a "$OUTPUT_FILE" | |
for (( concurrency=LOW_CONCURRENCY; concurrency<=HIGH_CONCURRENCY; concurrency+=CONCURRENCY_STEP )) | |
do | |
tempFile="temp/$PREFIX/c$concurrency-n$((NUM_CALL*concurrency)).log" | |
echo "$AB_PATH -c $concurrency -n $((NUM_CALL*concurrency)) $*" > "$tempFile" | |
startTime=$(date) | |
$AB_PATH -c $concurrency -n $((NUM_CALL*concurrency)) "$@" >> "$tempFile" 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Error: please check $tempFile" | |
exit 1 | |
fi | |
stats=$(egrep "Complete requests:|Failed requests:|Requests per second:|Total:" "$tempFile" | perl -pe 's/[^\d\.]+/ /g; s/^\s+//g;' | perl -pe 's/\s+$//g; s/\s+/,/g') | |
histogram=$(egrep "90%|95%|99%" "$tempFile" | cut -c6- | perl -pe 's/[^\d\.]+/ /g; s/^\s+//g;' | perl -pe 's/\s+$//g; s/\s+/,/g') | |
echo "$startTime,$concurrency,$stats,$histogram" | tee -a "$OUTPUT_FILE" | |
tcpConnections=$($SS_PATH -s | egrep 'TCP:' | perl -ne '/(\d+)/; print $1') | |
while [ $((tcpConnections+concurrency+CONCURRENCY_STEP)) -ge "$MAX_OPEN_FILES" ] | |
do | |
sleep 1 | |
tcpConnections=$($SS_PATH -s | egrep 'TCP:' | perl -ne '/(\d+)/; print $1') | |
done | |
done | |
rm -rf temp | |
echo "Finished benchmark, see $OUTPUT_FILE" |
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 13 in line 1.
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
#/usr/bin/ab -c CONCURRENCY=(100 to 1000 step 100) -n NUM=(100*CONCURRENCY) -k http://localhost/10k.dat | |
#start time,concurrency,complete requests,failed requests,tps,min,mean,stddev,median,max,90%,95%,99% | |
Sun Dec 14 18:21:10 CST 2014,100,10000,0,15096.25,0,7,7.4,4,44,16,19,39 | |
Sun Dec 14 18:21:10 CST 2014,200,20000,0,18577.21,0,11,18.0,7,212,21,31,65 | |
Sun Dec 14 18:21:12 CST 2014,300,30000,0,16152.28,0,18,22.4,13,140,49,65,92 | |
Sun Dec 14 18:21:14 CST 2014,400,40000,0,14630.17,0,27,38.0,18,276,62,97,205 | |
Sun Dec 14 18:21:16 CST 2014,500,50000,0,15889.28,0,31,53.1,12,426,83,138,282 | |
Sun Dec 14 18:21:20 CST 2014,600,60000,0,15234.23,0,39,50.7,29,491,84,120,262 | |
Sun Dec 14 18:21:24 CST 2014,700,70000,0,15745.20,0,44,63.2,30,533,97,137,359 | |
Sun Dec 14 18:21:28 CST 2014,800,80000,0,14514.44,0,55,59.0,46,543,122,156,263 | |
Sun Dec 14 18:21:34 CST 2014,900,90000,0,14184.83,0,63,81.3,44,687,139,191,402 | |
Sun Dec 14 18:21:40 CST 2014,1000,100000,0,14279.42,0,69,79.2,49,531,162,216,368 |
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
$ ./ab+.sh -k http://localhost/10k.dat | |
Starting benchmark | |
#/usr/bin/ab -c CONCURRENCY=(100 to 1000 step 100) -n NUM=(100*CONCURRENCY) -k http://localhost/10k.dat | |
#start time,concurrency,complete requests,failed requests,tps,min,mean,stddev,median,max,90%,95%,99% | |
Sun Dec 14 18:21:10 CST 2014,100,10000,0,15096.25,0,7,7.4,4,44,16,19,39 | |
Sun Dec 14 18:21:10 CST 2014,200,20000,0,18577.21,0,11,18.0,7,212,21,31,65 | |
Sun Dec 14 18:21:12 CST 2014,300,30000,0,16152.28,0,18,22.4,13,140,49,65,92 | |
Sun Dec 14 18:21:14 CST 2014,400,40000,0,14630.17,0,27,38.0,18,276,62,97,205 | |
Sun Dec 14 18:21:16 CST 2014,500,50000,0,15889.28,0,31,53.1,12,426,83,138,282 | |
Sun Dec 14 18:21:20 CST 2014,600,60000,0,15234.23,0,39,50.7,29,491,84,120,262 | |
Sun Dec 14 18:21:24 CST 2014,700,70000,0,15745.20,0,44,63.2,30,533,97,137,359 | |
Sun Dec 14 18:21:28 CST 2014,800,80000,0,14514.44,0,55,59.0,46,543,122,156,263 | |
Sun Dec 14 18:21:34 CST 2014,900,90000,0,14184.83,0,63,81.3,44,687,139,191,402 | |
Sun Dec 14 18:21:40 CST 2014,1000,100000,0,14279.42,0,69,79.2,49,531,162,216,368 | |
Finished benchmark, see localhost_20141214_1821.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment