benchmark-ab.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. declare -A THROUGHPUTS
  3. declare -A LATENCIES
  4. LOOP=5
  5. DOWNLOAD_HOST=$1
  6. DOWNLOAD_FILE=random/10K.1.html
  7. REQUESTS=10000
  8. CONCURRENCY_LIST="1 2 4 8 16 32 64 128 256"
  9. RESULT=result-$(date +%y%m%d-%H%M%S)
  10. touch $RESULT
  11. RUN=0
  12. while [ $RUN -lt $LOOP ]
  13. do
  14. for CONCURRENCY in $CONCURRENCY_LIST
  15. do
  16. rm -f OUTPUT
  17. echo "ab -n $REQUESTS -c $CONCURRENCY http://$DOWNLOAD_HOST/$DOWNLOAD_FILE"
  18. ab -n $REQUESTS -c $CONCURRENCY http://$DOWNLOAD_HOST/$DOWNLOAD_FILE > OUTPUT
  19. sleep 5
  20. THROUGHPUT=$(grep -m1 "Requests per second:" OUTPUT | awk '{ print $4 }')
  21. LATENCY=$(grep -m1 "Time per request:" OUTPUT | awk '{ print $4 }')
  22. THROUGHPUTS[$CONCURRENCY]="${THROUGHPUTS[$CONCURRENCY]} $THROUGHPUT"
  23. LATENCIES[$CONCURRENCY]="${LATENCIES[$CONCURRENCY]} $LATENCY"
  24. echo "concurrency=$CONCURRENCY, throughput=$THROUGHPUT, latency=$LATENCY"
  25. done
  26. RUN=$(expr $RUN + 1)
  27. done
  28. for CONCURRENCY in $CONCURRENCY_LIST
  29. do
  30. THROUGHPUT=$(echo ${THROUGHPUTS[$CONCURRENCY]} | tr " " "\n" | sort -n | awk '{a[NR]=$0}END{if(NR%2==1)print a[int(NR/2)+1];else print(a[NR/2-1]+a[NR/2])/2}')
  31. LATENCY=$(echo ${LATENCIES[$CONCURRENCY]} | tr " " "\n" | sort -n | awk '{a[NR]=$0}END{if(NR%2==1)print a[int(NR/2)+1];else print(a[NR/2-1]+a[NR/2])/2}')
  32. echo "$THROUGHPUT,$LATENCY" >> $RESULT
  33. done
  34. echo "Result file: $RESULT"