首页 > 其他 > 详细

写了一个简单的http benchmark脚本

时间:2014-03-15 04:49:31      阅读:526      评论:0      收藏:0      [点我收藏+]

apache benchmark只能测一个单一url,我用shell写了一个benchmark脚本,支持并发测试,指定参数,不过没有对响应时间和ret code做统计,适用在服务器端做精确统计的情况。


#! /bin/bash



concurrency=50
workdirectory=/tmp/httpbenchmark_workdir/
inputurlfile=


function usage() {
  echo "Http Benchmark is used for sending http request in pararrel."
  echo "Usage: ./http_benchmark.sh [-c int] [-i string] [-w string]"
  echo "-c: Specify concurrency number.(Default: 50)"
  echo "-i: Specify input file, if it‘s empty,then read from standard input.(Default: \"\")"
  echo "-w: Specify work directory.(Default: \"/tmp/httpbenchmark_workdir/\")"
}


function thread_run() {
  fileno=$1
  while read url
  do
    curl $url -s -o /dev/null
  done < ${workdirectory}/spilits_${fileno}.lst 
}


while getopts ‘c:i:w:h‘ OPTION
do
  case $OPTION in
    c) concurrency="$OPTARG"
       ;;
    i) inputurlfile="$OPTARG"
       ;;
    w) workdirectory="$OPTARG"
       ;;
    h) usage
       exit 0
       ;;
    ?) usage
       exit 1
       ;;
  esac
done
shift $((OPTIND - 1)) 


echo "Concurrency=${concurrency}"
echo "Workdirectory=${workdirectory}"
echo "InputUrlFile=${inputurlfile}"
rm -rf $workdirectory
mkdir -p $workdirectory


# split url list.
echo "Begin splitting urls..."
lineno=0
if [ -z $inputurlfile ]; then
  while read line
  do
    # as the ‘split‘ command differs between different distribution, we do it manually.
    if [ -n $line ]; then
      fileno=`expr $lineno % $concurrency`
      echo $line >> ${workdirectory}/spilits_${fileno}.lst
      let lineno=$lineno+1
    fi
  done
else
  while read line
  do
    # as the ‘split‘ command differs between different distribution, we do it manually.
    if [ -n $line ]; then
      fileno=`expr $lineno % $concurrency`
      echo $line >> ${workdirectory}/spilits_${fileno}.lst
      let lineno=$lineno+1
    fi
  done < $inputurlfile
fi
echo "Splitting done."


# ‘curl‘ in pararrel.
for i in `seq 1 $concurrency`
do
  let pos=$i-1
  thread_run $pos &
done


# wait
echo "Waiting subprocesses joined.."
wait
echo "Benchmark finished!Please inspect server log."


# clean work directory.
rm -rf $workdirectory

写了一个简单的http benchmark脚本,布布扣,bubuko.com

写了一个简单的http benchmark脚本

原文:http://blog.csdn.net/jollyjumper/article/details/21251981

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!