ApacheBench是 Apache 附帶的一個小工具,專門用於 HTTP Server 的benchmark testing,能夠同時模擬多個併發請求。html
ab的基本格式:nginx
NAME ab - Apache HTTP server benchmarking tool SYNOPSIS ab [ -A auth-username:password ] [ -b windowsize ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -u PUT-file ] [ -v verbosity] [ -V ] [ -w ] [ -x -attributes ] [ -X proxy[:port] ] [ -y -attributes ] [ -z -attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path 針對百度的一個簡單的測試以及結果: [root@nginx1 ~]# ab -n 100 -c 10 http://www.baidu.com/ ###-n:發出的請求數 -c:每次的併發數 This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/ Benchmarking www.baidu.com (be patient).....done Server Software: BWS/1.0 ###服務器的信息 Server Hostname: www.baidu.com ###域名 Server Port: 80 ###鏈接的端口 Document Path: / ###請求的URI Document Length: 10530 bytes ###第一次返回文檔的大小。若是文檔大小在測試的時候改變了,那麼這個響應會視爲一個錯誤。 Concurrency Level: 10 ###併發數 Time taken for tests: 29.32944 seconds ###開始到結束的時間 Complete requests: 100 ###成功的請求數 Failed requests: 42 ###失敗的請求數 (Connect: 0, Length: 42, Exceptions: 0) ###詳細的多少個鏈接失敗,長度異常,讀取失敗 Write errors: 0 ###在發送的時候失敗的次數 Total transferred: 1131908 bytes ###從服務器接收的字節數。這是明確的網絡發送字節。 HTML transferred: 1084140 bytes ###html內容傳輸量 Requests per second: 3.44 [#/sec] (mean) ###每秒請求數 Time per request: 2903.294 [ms] (mean) ###每一個併發的時間 Time per request: 290.329 [ms] (mean, across all concurrent requests) ###我的理解是每一個併發中每一個請求的時間 Transfer rate: 38.06 [Kbytes/sec] received ###每秒的網絡流量 Connection Times (ms) min mean[+/-sd] median max Connect: 37 1003 809.6 898 4056 ###socket發出請求到創建鏈接所花的時間。 Processing: 253 1713 861.2 1800 5643 ###鏈接創建後,直到http所有接收所用的時間。 Waiting: 42 759 711.5 715 4886 ###發送http完後,到接到第一個byte所等待的時間。 Total: 336 2717 1248.4 2739 6655 ###conn+processing ###下面的內容爲整個場景中全部請求的響應狀況。在場景中每一個請求都有一個響應時間,其中 50% 的用戶響應時間小於 3064 毫秒,60 % 的用戶響應時間小於 3094 毫秒,最大的響應時間小於 3184 毫秒 Percentage of the requests served within a certain time (ms) 50% 2739 66% 3017 75% 3141 80% 3187 90% 3998 95% 5607 98% 6095 99% 6655 100% 6655 (longest request)
更多參數: -A auth-username:password 有的請求須要用戶名和密碼進行驗證:(例如:401 驗證需求). -b windowsize TCP 發送和接收的buffer大小,單位是 bytes -c concurrency 併發數,同一時間有多少請求發出去,默認是1。 -C cookie-name=value 加上Cookie:以「 name=value 」的形式,能夠重複 -C xx1=yy1 -C xx2=yy2。 -d 不展現"percentage served within XX [ms] table". -e csv-file 寫一個逗號分隔的CSV文件,包含每一個百分比(from 1% to 100%)服務器執行的時間(毫秒),這個文件通常比'gunplot'有用。 -f protocol 指定 SSL/TLS 協議 (SSL2, SSL3, TLS1, or ALL). -g gnuplot-file 寫全部有用的信息到TSV(Tab separate values)文件,能夠輕鬆導入Excel等裏面,label在文件第一行。 -h 展現幫助信息 -H custom-header 加入額外的頭信息。以冒號分割,例如("Accept-Encoding: zip/zop;8bit") -i 發送GET請求 -k 打開Http的keepalive功能。在一個http會話裏執行多個請求。默認不開啓。 -n requests 要執行的請求校驗次數。默認請求一次,請求一次的結果不能表明校驗結果,不許確。 -p POST-file 包含POST數據文件 -P proxy-auth-username:password 支持基本Auth代理路由驗證。在(http code : 407 的時候須要) -q 當程序有150個請求,輸出以每10%或100個來顯示。-q 用來取消這些信息。 -r 在socket錯誤的時候不退出。 -s 若是用在SSl協議,功能還處在試驗階段,你不須要用它。 -S 不展現終止和標準值,也不展現警告信息。 -t timelimit 校驗花費的最大時間,內部設置-n 50000 次。使用這個選項在特定時間內測試。默認不開啓 -T content-type 用於POST/PUT 數據,例如eg. application/x-www-form-urlencoded. Default: text/plain. -u PUT-file PUT 的文件,記着加上-T -v verbosity 設置輸出等級, 4 輸出頭信息,3 輸出響應碼(404,200) 2 輸出警告和信息 -V 展現版本,而後退出。 -w 輸出結果到html裏的table,默認兩列,白色背景。 -x -attributes String to use as attributes for . Attributes are inserted . -X proxy[:port] 使用代理。 -y -attributes 設置屬性到 . -z -attributes 設置屬性到 . -Z ciphersuite 指定 SSL/TLS 密碼套件 (See openssl ciphers).
來源:http://blog.chinaunix.net/uid-14010457-id-3512262.htmlapache