ab命令原理
Apache的ab命令模擬多線程并發(fā)請(qǐng)求,測(cè)試服務(wù)器負(fù)載壓力,也可以測(cè)試nginx、lighthttp、IIS等其它Web服務(wù)器的壓力。
ab命令對(duì)發(fā)出負(fù)載的計(jì)算機(jī)要求很低,既不會(huì)占用很多CPU,也不會(huì)占用太多的內(nèi)存,但卻會(huì)給目標(biāo)服務(wù)器造成巨大的負(fù)載,因此是某些DDOS攻擊之必備良藥,老少皆宜。自己使用也須謹(jǐn)慎。否則一次上太多的負(fù)載,造成目標(biāo)服務(wù)器直接因內(nèi)存耗光死機(jī),而不得不硬重啟,得不償失。
在帶寬不足的情況下,最好是本機(jī)進(jìn)行測(cè)試,建議使用內(nèi)網(wǎng)的另一臺(tái)或者多臺(tái)服務(wù)器通過內(nèi)網(wǎng)進(jìn)行測(cè)試,這樣得出的數(shù)據(jù),準(zhǔn)確度會(huì)高很多。遠(yuǎn)程對(duì)web服務(wù)器進(jìn)行壓力測(cè)試,往往效果不理想(因?yàn)榫W(wǎng)絡(luò)延時(shí)過大或帶寬不足)
下載安裝:
http://mirror.bit.edu.cn/apache//httpd/binaries/win32/?C=M;O=A
找到 httpd-2.2.21-win32-x86-no_ssl.msi
參數(shù)文檔:
http://httpd.apache.org/docs/2.2/programs/ab.html
運(yùn)行:
在Windows系統(tǒng)下,打開cmd命令行窗口,定位到apache安裝目錄的bin目錄下
cd C:/Program Files (x86)/Apache Software Foundation/Apache2.2/bin
鍵入命令:
ab -n 800 -c 800 http://192.168.0.10/
(-n發(fā)出800個(gè)請(qǐng)求,-c模擬800并發(fā),相當(dāng)800人同時(shí)訪問,后面是測(cè)試url)
ab -t 60 -c 100 http://192.168.0.10/
在60秒內(nèi)發(fā)請(qǐng)求,一次100個(gè)請(qǐng)求。
//如果需要在url中帶參數(shù),這樣做
ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello.html
p.txt 是和ab.exe在一個(gè)目錄
p.txt 中可以寫參數(shù),如 p=wdp&fq=78
結(jié)果參數(shù)解釋:
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.0.10 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Finished 800 requests
Server Software: Microsoft-HTTPAPI/2.0
Server Hostname: 192.168.0.10
Server Port: 80
Document Path: /
Document Length: 315 bytes HTTP響應(yīng)數(shù)據(jù)的正文長(zhǎng)度
Concurrency Level: 800
Time taken for tests: 0.914 seconds 所有這些請(qǐng)求處理完成所花費(fèi)的時(shí)間
Complete requests: 800 完成請(qǐng)求數(shù)
Failed requests: 0 失敗請(qǐng)求數(shù)
新聞熱點(diǎn)
疑難解答
圖片精選