ab是Apache的一個安裝組件,所以需要下載Apache安裝後才能使用,該命令位於Apache安裝目錄下的bin文件夾中
ab是專門用於HTTP Server的benchmark testing,可以同時模擬多個併發請求
ab的設計意圖是描繪當前所安裝的Apache的執行性能,主要是顯示所安裝的Apache每秒可以處理多少個請求
ab不像LR那麼強大,但它足夠輕便,若只是在開發過程中想檢查一下某個模塊的響應情況,或者做一些場景比較簡單的測試,ab是個不錯的選擇
至少不用花費很多時間去學習LR中的那些複雜的功能,就更別說那License的價格了
下面簡單介紹下它的用法
查詢版本:[ab -V](注意這裏是大寫的V)
- [Jadyer@Jadyer-RHEL63 ~]$ ab -V
- 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/
查詢參數:[ab -v](注意這裏是小寫的v)
- [Jadyer@Jadyer-RHEL63 ~]$ ab -v
- ab: option requires an argument -- v
- ab: wrong number of arguments
- Usage: ab [options] [http[s]://]hostname[:port]/path
- Options are:
- //測試會話中所執行的請求個數,默認僅執行一個請求
- -n requests Number of requests to perform
- //一次產生的請求個數,即同一時間發出多少個請求,默認爲一次一個
- -c concurrency Number of multiple requests to make
- //測試所進行的最大秒數,默認爲無時間限制....其內部隱含值是[-n 50000],它可以使對服務器的測試限制在一個固定的總時間以內
- -t timelimit Seconds to max. wait for responses
- -b windowsize Size of TCP send/receive buffer, in bytes
- //包含了需要POST的數據的文件
- -p postfile File containing data to POST. Remember also to set -T
- -u putfile File containing data to PUT. Remember also to set -T
- //POST數據所使用的Content-type頭信息
- -T content-type Content-type header for POSTing, eg.
- 'application/x-www-form-urlencoded'
- Default is 'text/plain'
- //設置顯示信息的詳細程度,4或更大值會顯示頭信息,3或更大值可以顯示響應碼(404,200等),2或更大值可以顯示警告和其他信息
- -v verbosity How much troubleshooting info to print
- //以HTML表格的形式輸出結果,默認是白色背景的兩列寬度的一張表
- -w Print out results in HTML tables
- //執行HEAD請求,而不是GET
- -i Use HEAD instead of GET
- //設置<table>屬性的字符串,此屬性被填入<table 這裏>
- -x attributes String to insert as table attributes
- //設置<tr>屬性的字符串
- -y attributes String to insert as tr attributes
- //設置<td>屬性的字符串
- -z attributes String to insert as td or th attributes
- //對請求附加一個Cookie行,其典型形式是name=value的參數對,此參數可以重複
- -C attribute Add cookie, eg. 'Apache=1234. (repeatable)
- //對請求附加額外的頭信息,此參數的典型形式是一個有效的頭信息行,其中包含了以冒號分隔的字段和值的對(如"Accept-Encoding: zip/zop;8bit")
- -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
- Inserted after all normal header lines. (repeatable)
- //HTTP驗證,用冒號:分隔傳遞用戶名及密碼
- -A attribute Add Basic WWW Authentication, the attributes
- are a colon separated username and password.
- //對一箇中轉代理提供BASIC認證信任,用戶名和密碼由一個冒號:隔開,並以base64編碼形式發送
- //無論服務器是否需要(即是否發送了401認證需求代碼),此字符串都會被髮送
- -P attribute Add Basic Proxy Authentication, the attributes
- are a colon separated username and password.
- //對請求使用代理服務器
- -X proxy:port Proxyserver and port number to use
- //顯示版本號並退出
- -V Print version number and exit
- //啓用HTTP KeepAlive功能,即在一個HTTP會話中執行多個請求,默認爲不啓用KeepAlive功能
- -k Use HTTP KeepAlive feature
- //不顯示"percentage served within XX [ms] table"的消息(爲以前的版本提供支持)
- -d Do not show percentiles served table.
- //不顯示中值和標準背離值,且均值和中值爲標準背離值的1到2倍時,也不顯示警告或出錯信息,默認會顯示最小值/均值/最大值等(爲以前的版本提供支持)
- -S Do not show confidence estimators and warnings.
- //把所有測試結果寫入一個'gnuplot'或者TSV(以Tab分隔的)文件
- //此文件可以方便地導入到Gnuplot,IDL,Mathematica,Igor甚至Excel中,其中的第一行爲標題
- -g filename Output collected data to gnuplot format file.
- //產生一個以逗號分隔的(CSV)文件,其中包含了處理每個相應百分比的請求所需要(從1%到100%)的相應百分比的(以微妙爲單位)時間
- //由於這種格式已經"二進制化",所以比'gnuplot'格式更有用
- -e filename Output CSV file with percentages served
- -r Don't exit on socket receive errors.
- //顯示使用方法
- -h Display usage information (this message)
- -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
- -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]
- [Jadyer@Jadyer-RHEL63 ~]$ ab -n 1000 -c 10 https://epay.10010.com/
- 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 epay.10010.com (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
- Completed 900 requests
- Completed 1000 requests
- Finished 1000 requests
- //被測試Web服務軟件名稱,它來自於HTTP響應數據的頭信息(Apache-Coyote/1.1也就是Tomcat)
- Server Software: Apache-Coyote/1.1
- //服務器主機名,即請求的URL中的主機部分名稱
- Server Hostname: epay.10010.com
- //被測試Web服務器軟件的監聽端口
- Server Port: 443
- SSL/TLS Protocol: TLSv1/SSLv3,DHE-RSA-AES256-SHA,2048,256
- //請求URL的絕問文件路徑,即請求的資源
- Document Path: /
- //HTTP響應正文的長度,不包括響應頭,即減去了Total transferred中的HTML響應數據中頭信息的長度
- Document Length: 0 bytes
- //併發數(-c屬性來設置)
- Concurrency Level: 10
- //執行完所有的請求所花費的時間,即整個測試持續的時間
- Time taken for tests: 26.121 seconds
- //完成的請求數量
- Complete requests: 1000
- //失敗的請求數量
- Failed requests: 0
- Write errors: 0
- Non-2xx responses: 1001
- //整個場景中的網絡傳輸量,即所有請求的響應數據的總和,包含頭信息和正文長度
- Total transferred: 299299 bytes
- //整個場景中的HTML內容傳輸量,即所有請求中響應數據的正文長度,不包含頭信息的長度
- HTML transferred: 0 bytes
- //吞吐率:即每秒處理的請求數,相當於LR中的每秒事務數,括號中的mean表示這是一個平均值,其值爲Complete requests/Time taken for tests
- Requests per second: 38.28 [#/sec] (mean)
- //平均請求等待的時間:相當於LR中的平均事務響應時間,其值爲Time taken for tests/(Complete requests/Concurrency Level)
- Time per request: 261.206 [ms] (mean)
- //服務器平均請求處理的時間,即每個請求實際運行時間的平均值,其值爲Time per request/Concurrency Level
- Time per request: 26.121 [ms] (mean, across all concurrent requests)
- //平均每秒網絡上的流量,即這些請求在單位內從服務器獲取的數據長度,其值爲(Total transferred/Time taken for tests/)1024
- //這個統計選項可以很好的說明服務器在處理能力達到極限時其出口帶寬的需求量
- //可以幫助排除是否存在網絡流量過大導致響應時間延長的問題
- Transfer rate: 11.19 [Kbytes/sec] received
- //網絡上消耗的時間的分解,各項數據的具體算法還不是很清楚
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 85 222 101.0 205 1224
- Processing: 12 38 23.4 34 151
- Waiting: 12 37 23.5 33 151
- Total: 144 259 100.9 244 1268
- //整個場景中所有請求的響應情況,在場景中每個請求都有一個響應時間
- //下面結果表明,50%的用戶響應時間(即請求處理時間,這裏處理時間是指Time per request)小於244毫秒
- //66%的用戶響應時間小於252毫秒,而最大的響應時間小於1268毫秒
- //對於併發請求,實際上CPU並不是同時處理的,而是按照每個請求獲得的時間片而逐個輪轉處理的
- //所以基本上第一個Time per request時間約等於第二個Time per request時間乘以併發請求數
- Percentage of the requests served within a certain time (ms)
- 50% 244
- 66% 252
- 75% 254
- 80% 255
- 90% 260
- 95% 481
- 98% 665
- 99% 686
- 100% 1268 (longest request)
獲取網站信息
- [Jadyer@Jadyer-RHEL63 ~]$ curl -Is https://epay.10010.com/
- HTTP/1.1 302 Moved Temporarily
- Date: Tue, 06 Nov 2012 17:52:13 GMT
- Server: Apache-Coyote/1.1
- Location: http://epay.10010.com/404.jsp
- Content-Type: text/vnd.wap.wml;chartset=gbk;charset=GBK
- Set-Cookie: JSESSIONID=9DDBCA78C7FEF4ABECD070E744CE926C; Path=/