Apache Bench安装与使用
轉載:ApacheBench(ab)使用詳解
一、Apache Bench簡介
ApacheBench 是 Apache 服務器自帶的一個web壓力測試工具,簡稱ab。ab又是一個命令行工具,對發起負載的本機要求很低,根據ab命令可以創建很多的并發訪問線程,模擬多個訪問者同時對某一URL地址進行訪問,因此可以用來測試目標服務器的負載壓力。它的測試目標是基于URL的,因此,既可以用來測試Apache的負載壓力,也可以測試nginx、lighthttp、tomcat、IIS等其它Web服務器的壓力。總的來說ab工具小巧簡單,上手學習較快,可以提供需要的基本性能指標,但是沒有圖形化結果,不能監控。
ab命令對發出負載的計算機要求很低,既不會占用很高CPU,也不會占用很多內存,但卻會給目標服務器造成巨大的負載,其原理類似CC攻擊。自己測試使用也須注意,否則一次上太多的負載,可能造成目標服務器因資源耗完,嚴重時甚至導致死機。
二、Apache Bench安裝
首先需要安裝Apache服務器,下載地址:https://www.apachelounge.com/download/,
建議下載最新版本的,因為舊版本的ab不支持-r參數。
三、Apache Bench使用
1.使用例子:
?步驟1:找到安裝Apache Bench文件的bin目錄下,輸入ab.exe 可以看到提示信息如下:
?步驟2:
輸入?ab -n 100 -c 20?http://localhost:8080/jsrWeb/index.html(-n發出100個請求,-c模擬20并發,相當100人同時訪問,后面是測試url)
輸入?ab -n 100 -c 20?http://localhost:8080/jsrAdminWeb/test?str=AA?(傳入一個參數)
輸入?ab -n 100 -c 20 -T "text/plain" -p test.txt http://localhost:8080/jsrAdminWeb/test (傳入多個參數,test.txt文件與ab.exe在同目錄下,test.txt文件里寫str1=AA&str2=BB)
輸入?ab -n 100 -c 20 -T "text/plain" -p E:\DOWNLOAD\httpd-2.4.33-Win64-VC15\Apache24\test.txt http://localhost:8080/jsrAdminWeb/test?(傳入多個參數,test.txt文件與ab.exe不在同目錄下,寫入test.txt文件的全路徑)
輸入 ab -t 60 -c 20?http://localhost:8080/jsrWeb/index.html ( 在60秒內發請求,一次20個請求)
結果參數解釋(轉載):?
Server Software:??????? Microsoft-HTTPAPI/2.0?
Server Hostname:??????? 192.168.0.10?
Server Port:??????????? 80
Document Path:????????? /?
Document Length:??????? 315 bytes???????HTTP響應數據的正文長度
Concurrency Level:????? 800?
Time taken for tests:?? 0.914 seconds????所有這些請求處理完成所花費的時間?
Complete requests:????? 800?????????????完成請求數?
Failed requests:??????? 0????????????????失敗請求數?
Write errors:?????????? 0????????????????
Non-2xx responses:????? 800?
Total transferred:????? 393600 bytes?????網絡總傳輸量?
HTML transferred:?????? 252000 bytes?????HTML內容傳輸量?
Requests per second:??? 875.22 [#/sec] (mean)?吞吐量-每秒請求數?
Time per request:?????? 914.052 [ms] (mean)??服務器收到請求,響應頁面要花費的時間?
Time per request:?????? 1.143 [ms] (mean, across all concurrent requests)?并發的每個請求平均消耗時間?
Transfer rate:????????? 420.52 [Kbytes/sec] received?平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題
網絡上消耗的時間的分解:?
Connection Times (ms)?
????????????? min? mean[+/-sd] median?? max?
Connect:??????? 0??? 1?? 0.5????? 1?????? 3?
Processing:?? 245? 534 125.2??? 570???? 682?
Waiting:?????? 11? 386 189.1??? 409???? 669?
Total:??????? 246? 535 125.0??? 571???? 684
整個場景中所有請求的響應情況。在場景中每個請求都有一個響應時間?
其中 50% 的用戶響應時間小于 571 毫秒?
80 % 的用戶響應時間小于 652 毫秒?
最大的響應時間小于 684 毫秒?
Percentage of the requests served within a certain time (ms)?
? 50%??? 571?
? 66%??? 627?
? 75%??? 646?
? 80%??? 652?
? 90%??? 666?
? 95%??? 677?
? 98%??? 681?
? 99%??? 682?
100%??? 684 (longest request)
2.ApacheBench的參數說明
1 格式:ab [options] [http://]hostname[:port]/path 2 參數說明: 3 -n requests Number of requests to perform 4 //在測試會話中所執行的請求個數(本次測試總共要訪問頁面的次數)。默認時,僅執行一個請求。 5 -c concurrency Number of multiple requests to make 6 //一次產生的請求個數(并發數)。默認是一次一個。 7 -t timelimit Seconds to max. wait for responses 8 //測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。 9 -p postfile File containing data to POST 10 //包含了需要POST的數據的文件,文件格式如“p1=1&p2=2”.使用方法是 -p 111.txt 。 (配合-T) 11 -T content-type Content-type header for POSTing 12 //POST數據所使用的Content-type頭信息,如 -T “application/x-www-form-urlencoded” 。 (配合-p) 13 -v verbosity How much troubleshooting info to print 14 //設置顯示信息的詳細程度 – 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號并退出。 15 -w Print out results in HTML tables 16 //以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。 17 -i Use HEAD instead of GET 18 // 執行HEAD請求,而不是GET。 19 -x attributes String to insert as table attributes 20 -y attributes String to insert as tr attributes 21 -z attributes String to insert as td or th attributes 22 -C attribute Add cookie, eg. -C “c1=1234,c2=2,c3=3″ (repeatable) 23 //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重復,用逗號分割。 24 提示:可以借助session實現原理傳遞 JSESSIONID參數, 實現保持會話的功能,如 25 -C ” c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。 26 -H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable) 27 -A attribute Add Basic WWW Authentication, the attributes 28 are a colon separated username and password. 29 -P attribute Add Basic Proxy Authentication, the attributes 30 are a colon separated username and password. 31 //-P proxy-auth-username:password 對一個中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,并以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被發送。 32 -X proxy:port Proxyserver and port number to use 33 -V Print version number and exit 34 -k Use HTTP KeepAlive feature 35 -d Do not show percentiles served table. 36 -S Do not show confidence estimators and warnings. 37 -g filename Output collected data to gnuplot format file. 38 -e filename Output CSV file with percentages served 39 -h Display usage information (this message) 40 //-attributes 設置屬性的字符串. 缺陷程序中有各種靜態聲明的固定長度的緩沖區。另外,對命令行參數、服務器的響應頭和其他外部輸入的解析也很簡單,這可能會有不良后果。它沒有完整地實現 HTTP/1.x; 僅接受某些’預想’的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即你可能是在測試ab而不是服務器的性能。?
轉載于:https://www.cnblogs.com/nananana/p/8748941.html
總結
以上是生活随笔為你收集整理的Apache Bench安装与使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苏武传特殊句式及其翻译
- 下一篇: [virtualenvwrapper]