apache中ab壓力測(cè)試工具怎么用-創(chuàng)新互聯(lián)

這篇文章主要介紹apache中ab壓力測(cè)試工具怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作與策劃設(shè)計(jì),京山網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:京山等地區(qū)。京山做網(wǎng)站價(jià)格咨詢:18980820575

一、腳本說(shuō)明

該腳本支持ab大多常用參數(shù),如果你需要更多參數(shù),可以通過(guò)修改本腳本,加入你想要的即可。

該腳本支持:

1)、批量測(cè)試。注意,并不是簡(jiǎn)單的批量測(cè)試,你可以定測(cè)測(cè)試輪數(shù),間隔時(shí)間。
2)、階梯并發(fā)增長(zhǎng)定制測(cè)試,如并發(fā)從100到1000,每輪測(cè)5次等。
3)、支持ab的post file模式,你只要在參數(shù)-P | --postfile中帶上你的數(shù)據(jù)文件即可。
4)、壓測(cè)完指標(biāo)分析顯示,本shell可以將ab中常用的指示即時(shí)分析出來(lái)。

apache中ab壓力測(cè)試工具怎么用


二、腳本內(nèi)容

#!/bin/bash
echo '*===================================================*'
echo '| 本腳本工具基于ab(Apache benchmark),請(qǐng)先安裝好ab, awk |'
echo '| 注意: |' 
echo '| shell默認(rèn)大客戶端數(shù)為1024 |'
echo '| 如超出此限制,請(qǐng)執(zhí)行以下命令: |'
echo '| ulimit -n 655350 |'
echo '*===================================================*'
function usage() {
 echo ' 命令格式:'
 echo ' ab-test-tools.sh'
 echo ' -N|--count 總請(qǐng)求數(shù),缺省 : 5w'
 echo ' -C|--clients 并發(fā)數(shù), 缺省 : 100'
 echo ' -R|--rounds 測(cè)試次數(shù), 缺省 : 10 次'
 echo ' -S|-sleeptime 間隔時(shí)間, 缺省 : 10 秒'
 echo ' -I|--min 最小并發(fā)數(shù), 缺省: 0'
 echo ' -X|--max 大并發(fā)數(shù),缺省: 0'
 echo ' -J|--step 次遞增并發(fā)數(shù)'
 echo ' -T|--runtime 總體運(yùn)行時(shí)間,設(shè)置此項(xiàng)時(shí)大請(qǐng)求數(shù)為5w' 
 echo ' -P|--postfile post數(shù)據(jù)文件路徑'
 echo ' -U|--url 測(cè)試地址'
 echo ''
 echo ' 測(cè)試輸出結(jié)果*.out文件'
 exit;
}
# 定義默認(rèn)參數(shù)量
# 總請(qǐng)求數(shù)
count=50000
# 并發(fā)數(shù)
clients=100O
# 測(cè)試輪數(shù)
rounds=10
# 間隔時(shí)間
sleeptime=10
# 最小并發(fā)數(shù)
min=0
# 大數(shù)發(fā)數(shù)
max=0
# 并發(fā)遞增數(shù)
step=0
# 測(cè)試地址
url=''
# 測(cè)試限制時(shí)間
runtime=0
# 傳輸數(shù)據(jù)
postfile=''
ARGS=`getopt -a -o N:C:R:S:I:X:J:U:T:P:h -l count:,client:,round:,sleeptime:,min:,max:,step:,runtime:,postfile:,help -- "$@"`
[ $? -ne 0 ] && usage
eval set -- "${ARGS}" 
while true 
do
 case "$1" in
 -N|--count)
 count="$2"
 shift
 ;;
 
 -C|--client)
 clients="$2"
 shift
 ;;
 -R|--round)
 rounds="$2"
 shift
 ;;
 -S|--sleeptime)
 sleeptime="$2"
 shift
 ;;
 -I|--min)
 min="$2"
 shift
 ;;
 -X|--max)
 max="$2"
 shift
 ;;
 -J|--step)
 step="$2"
 shift
 ;;
 -U|--url)
 url="$2"
 shift
 ;;
 -T|--runtime)
 runtime="$2"
 shift
 ;;
 -P|--postfile)
 postfile="$2"
 shift
 ;;
 -h|--help)
 usage
 ;;
 --)
 shift
 break
 ;;
 esac
shift
done
# 參數(shù)檢查
if [ x$url = x ]
then
 echo '請(qǐng)輸入測(cè)試url,非文件/以為結(jié)束'
 exit
fi
flag=0
if [ $min != 0 -a $max != 0 ]
then 
 if [ $max -le $min ] 
 then
 echo '大并發(fā)數(shù)不能小于最小并發(fā)數(shù)'
 exit
 fi
 if [ $step -le 0 ]
 then
 echo '并發(fā)遞增步長(zhǎng)不能<=0'
 exit
 fi
 if [ $min -lt $max ]
 then
 flag=1
 fi
fi
# 生成ab命令串
cmd="ab -k -r"
# 數(shù)據(jù)文件
if [ x$postf != x ]
then
 cmd="$cmd -p $postf"
fi
if [ x$tl != x -a $tl != 0 ]
then 
 max=50000;
 cmd="$cmd -t$tl"
fi
cmd="$cmd -n$count"
echo '-----------------------------';
echo '測(cè)試參數(shù)';
echo " 總請(qǐng)求數(shù):$count";
echo " 并發(fā)數(shù):$clients";
echo " 重復(fù)次數(shù):$rounds 次";
echo " 間隔時(shí)間:$sleeptime 秒";
echo " 測(cè)試地址:$url";
if [ $min != 0 ];then
echo " 最小并發(fā)數(shù):$min";
fi
if [ $max != 0 ];then
echo " 大并發(fā)數(shù):$max";
fi
if [ $step != 0 ];then
echo " 每輪并發(fā)遞增:$step" 
fi
# 指定輸出文件名
datestr=`date +%Y%m%d%H%I%S`
outfile="$datestr.out";
# runtest $cmd $outfile $rounds $sleeptime
function runtest() {
 # 輸出命令
 echo "";
 echo ' 當(dāng)前執(zhí)行命令:'
 echo " $cmd"
 echo '------------------------------'
 # 開(kāi)始執(zhí)行測(cè)試
 cnt=1
 while [ $cnt -le $rounds ];
 do
 echo "第 $cnt 輪 開(kāi)始"
 $cmd >> $outfile 
 echo "
" >> $outfile
 echo "第 $cnt 輪 結(jié)束"
 echo '----------------------------'
 cnt=$(($cnt+1))
 if [ $cnt -le $rounds ]; then
 echo "等待 $sleeptime 秒"
 sleep $sleeptime
 fi 
 done
}
temp=$cmd;
if [ $flag != 0 ]; then
 cur=$min
 over=0
 while [ $cur -le $max ]
 do
 cmd="$temp -c$cur $url"
 runtest $cmd $outfile $rounds $sleeptime 
 cur=$(($cur+$step))
 if [ $cur -ge $max -a $over != 1 ]; then
 cur=$max 
 over=1
 fi
 done
else 
 cmd="$cmd -c$clients $url"
 runtest $cmd $outfile $rounds $sleeptime 
fi
# 分析結(jié)果
if [ -f $outfile ]; then
echo '本次測(cè)試結(jié)果如下:'
echo '+------+----------+----------+---------------+---------------+---------------+--------------------+--------------------+'
echo '| 序號(hào) | 總請(qǐng)求數(shù) | 并發(fā)數(shù) | 失敗請(qǐng)求數(shù) | 每秒事務(wù)數(shù) | 平均事務(wù)(ms) | 并發(fā)平均事務(wù)數(shù)(ms) |  總體傳輸字節(jié)數(shù) |'
echo '+------+----------+----------+---------------+---------------+---------------+--------------------+--------------------+'
comp=(`awk '/Complete requests/{print $NF}' $outfile`) 
concur=(`awk '/Concurrency Level:/{print $NF}' $outfile`)
fail=(`awk '/Failed requests/{print $NF}' $outfile`)
qps=(`awk '/Requests per second/{print $4F}' $outfile`)
tpr=(`awk '/^Time per request:(.*)(mean)$/{print $4F}' $outfile`)
tpr_c=(`awk '/Time per request(.*)(mean, across all concurrent requests)/{print $4F}' $outfile`)
trate=(`awk '/Transfer rate/{print $3F}' $outfile`)
for ((i=0; i<${#comp[@]}; i++))
do
 echo -n "|"
 printf '%6s' $(($i+1)) 
 printf "|"
 printf '%10s' ${comp[i]}
 printf '|'
 
 printf '%10s' ${concur[i]}
 printf '|'
 printf '%15s' ${fail[i]}
 printf '|'
 printf '%15s' ${qps[i]}
 printf '|'
 printf '%15s' ${tpr[i]}
 printf '|'
 printf '%20s' ${tpr_c[i]}
 printf '|'
 printf '%20s' ${trate[i]}
 printf '|'
 echo '';
 echo '+-----+----------+----------+---------------+---------------+---------------+--------------------+--------------------+'
done
echo ''
fi

三、測(cè)試示例

sh ab-test-tool.sh -N 100000 -C 100 -R 2 -I 100 -X 500 -J 80 -S 5 -U 'http://...'

apache中ab壓力測(cè)試工具怎么用


四、ab信息說(shuō)明

Server Software:    Apache/2.2.19  ##apache版本 
Server Hostname:    vm1.xxx.com  ##請(qǐng)求的機(jī)子 
Server Port:      80 ##請(qǐng)求端口

Document Path:     /xxx.html 
Document Length:    25 bytes ##頁(yè)面長(zhǎng)度

Concurrency Level:   100 ##并發(fā)數(shù) 
Time taken for tests:  0.273 seconds ##共使用了多少時(shí)間 
Complete requests:   1000  ##請(qǐng)求數(shù) 
Failed requests:    0  ##失敗請(qǐng)求 
Write errors:      0  
Total transferred:   275000 bytes ##總共傳輸字節(jié)數(shù),包含http的頭信息等 
HTML transferred:    25000 bytes ##html字節(jié)數(shù),實(shí)際的頁(yè)面?zhèn)鬟f字節(jié)數(shù) 
Requests per second:  3661.60 [#/sec] (mean) ##每秒多少請(qǐng)求,這個(gè)是非常重要的參數(shù)數(shù)值,服務(wù)器的吞吐量 
Time per request:    27.310 [ms] (mean) ##用戶平均請(qǐng)求等待時(shí)間 
Time per request:    0.273 [ms] (mean, across all concurrent requests) ##服務(wù)器平均處理時(shí)間,也就是服務(wù)器吞吐量的倒數(shù) 
Transfer rate:     983.34 [Kbytes/sec] received ##每秒獲取的數(shù)據(jù)長(zhǎng)度

Connection Times (ms) 
       min mean[+/-sd] median  max 
Connect:    0  1  2.3   0   16 
Processing:   6  25  3.2   25   32 
Waiting:    5  24  3.2   25   32 
Total:     6  25  4.0   25   48

Percentage of the requests served within a certain time (ms) 
 50%   25 ## 50%的請(qǐng)求在25ms內(nèi)返回 
 66%   26 ## 60%的請(qǐng)求在26ms內(nèi)返回 
 75%   26 
 80%   26 
 90%   27 
 95%   31 
 98%   38 
 99%   43 
100%   48 (longest request)

以上是“apache中ab壓力測(cè)試工具怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

新聞名稱:apache中ab壓力測(cè)試工具怎么用-創(chuàng)新互聯(lián)
標(biāo)題URL:http://www.muchs.cn/article12/dhjdgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站云服務(wù)器、外貿(mào)網(wǎng)站建設(shè)、用戶體驗(yàn)、動(dòng)態(tài)網(wǎng)站、App開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)