Apache的壓力測試工具ab

ab是Apache自帶的HTTP壓力測試工具,全稱是ApacheBench,同微軟的WAST、惠普的LoadRunner、QALoad等比起來,它要方便易用得多
ab是Apache的一個安裝組件,所以需要下載Apache安裝後才能使用,該命令位於Apache安裝目錄下的bin文件夾中
ab是專門用於HTTP Server的benchmark testing,可以同時模擬多個併發請求
ab的設計意圖是描繪當前所安裝的Apache的執行性能,主要是顯示所安裝的Apache每秒可以處理多少個請求

ab不像LR那麼強大,但它足夠輕便,若只是在開發過程中想檢查一下某個模塊的響應情況,或者做一些場景比較簡單的測試,ab是個不錯的選擇
至少不用花費很多時間去學習LR中的那些複雜的功能,就更別說那License的價格了


下面簡單介紹下它的用法


查詢版本:[ab -V](注意這裏是大寫的V)

  1. [Jadyer@Jadyer-RHEL63 ~]$ ab -V  
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  4. Licensed to The Apache Software Foundation, http://www.apache.org/  

查詢參數:[ab -v](注意這裏是小寫的v)

  1. [Jadyer@Jadyer-RHEL63 ~]$ ab -v  
  2. ab: option requires an argument -- v  
  3. ab: wrong number of arguments  
  4. Usage: ab [options] [http[s]://]hostname[:port]/path  
  5. Options are:  
  6.     //測試會話中所執行的請求個數,默認僅執行一個請求  
  7.     -n requests     Number of requests to perform  
  8.     //一次產生的請求個數,即同一時間發出多少個請求,默認爲一次一個  
  9.     -c concurrency  Number of multiple requests to make  
  10.     //測試所進行的最大秒數,默認爲無時間限制....其內部隱含值是[-n 50000],它可以使對服務器的測試限制在一個固定的總時間以內  
  11.     -t timelimit    Seconds to max. wait for responses  
  12.     -b windowsize   Size of TCP send/receive buffer, in bytes  
  13.     //包含了需要POST的數據的文件  
  14.     -p postfile     File containing data to POST. Remember also to set -T  
  15.     -u putfile      File containing data to PUT. Remember also to set -T  
  16.     //POST數據所使用的Content-type頭信息  
  17.     -T content-type Content-type header for POSTing, eg.  
  18.                     'application/x-www-form-urlencoded'  
  19.                     Default is 'text/plain'  
  20.     //設置顯示信息的詳細程度,4或更大值會顯示頭信息,3或更大值可以顯示響應碼(404,200等),2或更大值可以顯示警告和其他信息  
  21.     -v verbosity    How much troubleshooting info to print  
  22.     //以HTML表格的形式輸出結果,默認是白色背景的兩列寬度的一張表  
  23.     -w              Print out results in HTML tables  
  24.     //執行HEAD請求,而不是GET  
  25.     -i              Use HEAD instead of GET  
  26.     //設置<table>屬性的字符串,此屬性被填入<table 這裏>  
  27.     -x attributes   String to insert as table attributes  
  28.     //設置<tr>屬性的字符串  
  29.     -y attributes   String to insert as tr attributes  
  30.     //設置<td>屬性的字符串  
  31.     -z attributes   String to insert as td or th attributes  
  32.     //對請求附加一個Cookie行,其典型形式是name=value的參數對,此參數可以重複  
  33.     -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)  
  34.     //對請求附加額外的頭信息,此參數的典型形式是一個有效的頭信息行,其中包含了以冒號分隔的字段和值的對(如"Accept-Encoding: zip/zop;8bit")  
  35.     -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'  
  36.                     Inserted after all normal header lines. (repeatable)  
  37.     //HTTP驗證,用冒號:分隔傳遞用戶名及密碼  
  38.     -A attribute    Add Basic WWW Authentication, the attributes  
  39.                     are a colon separated username and password.  
  40.     //對一箇中轉代理提供BASIC認證信任,用戶名和密碼由一個冒號:隔開,並以base64編碼形式發送  
  41.     //無論服務器是否需要(即是否發送了401認證需求代碼),此字符串都會被髮送  
  42.     -P attribute    Add Basic Proxy Authentication, the attributes  
  43.                     are a colon separated username and password.  
  44.     //對請求使用代理服務器  
  45.     -X proxy:port   Proxyserver and port number to use  
  46.     //顯示版本號並退出  
  47.     -V              Print version number and exit  
  48.     //啓用HTTP KeepAlive功能,即在一個HTTP會話中執行多個請求,默認爲不啓用KeepAlive功能  
  49.     -k              Use HTTP KeepAlive feature  
  50.     //不顯示"percentage served within XX [ms] table"的消息(爲以前的版本提供支持)  
  51.     -d              Do not show percentiles served table.  
  52.     //不顯示中值和標準背離值,且均值和中值爲標準背離值的1到2倍時,也不顯示警告或出錯信息,默認會顯示最小值/均值/最大值等(爲以前的版本提供支持)  
  53.     -S              Do not show confidence estimators and warnings.  
  54.     //把所有測試結果寫入一個'gnuplot'或者TSV(以Tab分隔的)文件  
  55.     //此文件可以方便地導入到Gnuplot,IDL,Mathematica,Igor甚至Excel中,其中的第一行爲標題  
  56.     -g filename     Output collected data to gnuplot format file.  
  57.     //產生一個以逗號分隔的(CSV)文件,其中包含了處理每個相應百分比的請求所需要(從1%到100%)的相應百分比的(以微妙爲單位)時間  
  58.     //由於這種格式已經"二進制化",所以比'gnuplot'格式更有用  
  59.     -e filename     Output CSV file with percentages served  
  60.     -r              Don't exit on socket receive errors.  
  61.     //顯示使用方法  
  62.     -h              Display usage information (this message)  
  63.     -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)  
  64.     -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)  

測試網站:[ab -n 1000 -c 10 http://192.168.8.35:9000/noCardNoPasswordSign]

-n表示總共發送的請求數
-c表示每次併發的請求數
使用ab測試時,其支持的最大併發數是沒有限制的,但實際值要取決於Linux允許每個進程打開的最大文件數,即[ulimit -n]

  1. [Jadyer@Jadyer-RHEL63 ~]$ ab -n 1000 -c 10 https://epay.10010.com/  
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  4. Licensed to The Apache Software Foundation, http://www.apache.org/  
  5.   
  6. Benchmarking epay.10010.com (be patient)  
  7. Completed 100 requests  
  8. Completed 200 requests  
  9. Completed 300 requests  
  10. Completed 400 requests  
  11. Completed 500 requests  
  12. Completed 600 requests  
  13. Completed 700 requests  
  14. Completed 800 requests  
  15. Completed 900 requests  
  16. Completed 1000 requests  
  17. Finished 1000 requests  
  18.   
  19.   
  20. //被測試Web服務軟件名稱,它來自於HTTP響應數據的頭信息(Apache-Coyote/1.1也就是Tomcat)  
  21. Server Software:        Apache-Coyote/1.1  
  22. //服務器主機名,即請求的URL中的主機部分名稱  
  23. Server Hostname:        epay.10010.com  
  24. //被測試Web服務器軟件的監聽端口  
  25. Server Port:            443  
  26. SSL/TLS Protocol:       TLSv1/SSLv3,DHE-RSA-AES256-SHA,2048,256  
  27.   
  28. //請求URL的絕問文件路徑,即請求的資源  
  29. Document Path:          /  
  30. //HTTP響應正文的長度,不包括響應頭,即減去了Total transferred中的HTML響應數據中頭信息的長度  
  31. Document Length:        0 bytes  
  32.   
  33. //併發數(-c屬性來設置)  
  34. Concurrency Level:      10  
  35. //執行完所有的請求所花費的時間,即整個測試持續的時間  
  36. Time taken for tests:   26.121 seconds  
  37. //完成的請求數量  
  38. Complete requests:      1000  
  39. //失敗的請求數量  
  40. Failed requests:        0  
  41. Write errors:           0  
  42. Non-2xx responses:      1001  
  43. //整個場景中的網絡傳輸量,即所有請求的響應數據的總和,包含頭信息和正文長度  
  44. Total transferred:      299299 bytes  
  45. //整個場景中的HTML內容傳輸量,即所有請求中響應數據的正文長度,不包含頭信息的長度  
  46. HTML transferred:       0 bytes  
  47. //吞吐率:即每秒處理的請求數,相當於LR中的每秒事務數,括號中的mean表示這是一個平均值,其值爲Complete requests/Time taken for tests  
  48. Requests per second:    38.28 [#/sec] (mean)  
  49. //平均請求等待的時間:相當於LR中的平均事務響應時間,其值爲Time taken for tests/(Complete requests/Concurrency Level)  
  50. Time per request:       261.206 [ms] (mean)  
  51. //服務器平均請求處理的時間,即每個請求實際運行時間的平均值,其值爲Time per request/Concurrency Level  
  52. Time per request:       26.121 [ms] (mean, across all concurrent requests)  
  53. //平均每秒網絡上的流量,即這些請求在單位內從服務器獲取的數據長度,其值爲(Total transferred/Time taken for tests/)1024  
  54. //這個統計選項可以很好的說明服務器在處理能力達到極限時其出口帶寬的需求量  
  55. //可以幫助排除是否存在網絡流量過大導致響應時間延長的問題  
  56. Transfer rate:          11.19 [Kbytes/sec] received  
  57.   
  58. //網絡上消耗的時間的分解,各項數據的具體算法還不是很清楚  
  59. Connection Times (ms)  
  60.               min  mean[+/-sd] median   max  
  61. Connect:       85  222 101.0    205    1224  
  62. Processing:    12   38  23.4     34     151  
  63. Waiting:       12   37  23.5     33     151  
  64. Total:        144  259 100.9    244    1268  
  65.   
  66. //整個場景中所有請求的響應情況,在場景中每個請求都有一個響應時間  
  67. //下面結果表明,50%的用戶響應時間(即請求處理時間,這裏處理時間是指Time per request)小於244毫秒  
  68. //66%的用戶響應時間小於252毫秒,而最大的響應時間小於1268毫秒  
  69. //對於併發請求,實際上CPU並不是同時處理的,而是按照每個請求獲得的時間片而逐個輪轉處理的  
  70. //所以基本上第一個Time per request時間約等於第二個Time per request時間乘以併發請求數  
  71. Percentage of the requests served within a certain time (ms)  
  72.   50%    244  
  73.   66%    252  
  74.   75%    254  
  75.   80%    255  
  76.   90%    260  
  77.   95%    481  
  78.   98%    665  
  79.   99%    686  
  80.  100%   1268 (longest request)  

獲取網站信息

  1. [Jadyer@Jadyer-RHEL63 ~]$ curl -Is https://epay.10010.com/  
  2. HTTP/1.1 302 Moved Temporarily  
  3. Date: Tue, 06 Nov 2012 17:52:13 GMT  
  4. Server: Apache-Coyote/1.1  
  5. Location: http://epay.10010.com/404.jsp  
  6. Content-Type: text/vnd.wap.wml;chartset=gbk;charset=GBK  
  7. Set-Cookie: JSESSIONID=9DDBCA78C7FEF4ABECD070E744CE926C; Path=/  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章