ApacheBench(ab)使用簡介

ApacheBench 主要是用來測試阿帕奇服務器執行效率用的。安裝好 apache 服務器套件後,進入 bin 目錄,就可以找到該可執行文件 ab.exe 。

         ApacheBench 可以針對某一特定 URL 模擬出連續的聯機請求,同時還可以仿真出同時間點個數相同的聯機請求,因而利用 ApacheBench 可幫助我們在網站開發期間仿真實際上線可能的情況,利用仿真出來的數據做爲調整服務器設定或程序的依據。

ab 用法如下

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 #同一時間發出多少個請求(並行連接)
    -t timelimit    Seconds to max. wait for responses
    -p postfile     File containing data to POST
    -T content-type Content-type header for POSTing
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -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
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -s              Use httpS instead of HTTP (SSL)
    -h              Display usage information (this message)

基本用法 :
ab -n 全部請求數 -c 併發數 測試 url
例 :ab -n 1000 -c 50 http://www.abc.com/a.php
得到結果類似於 ( 後面顏色字爲中文翻譯 ):
Server Software:        Apache/2.0.55
Server Hostname:        localhost
Server Port:            80
Document Path:          /1.php
Document Length:        82522 bytes  # 請求文檔大小
Concurrency Level:      50           # 併發數
Time taken for tests:   92.76140 seconds # 全部請求完成耗時
Complete requests:      10000          # 全部請求數
Failed requests:        1974           # 失敗的請求
  (Connect: 0, Length: 1974, Exceptions: 0)
Write errors:           0
Total transferred:      827019400 bytes   # 總傳輸大小
HTML transferred:       825219400 bytes
Requests per second:    108.61 [#/sec] (mean)   # 每秒請求數 ( 平均 )
Time per request:       460.381 [ms] (mean)   # 每次併發請求時間 ( 所有併發 )
Time per request:       9.208 [ms] (mean, across all concurrent requests)   # 每一請求時間 ( 併發平均 )  
Transfer rate:          8771.39 [Kbytes/sec] received    # 傳輸速率
Connection Times (ms)    # 連接時間
             min  mean[+/-sd] median   max
Connect(# 連接 ):        0    0   2.1      0      46
Processing(# 處理 ):    31  458  94.7    438    1078
Waiting(# 等待 ):       15  437  87.5    422     938
Total:         31  458  94.7    438    1078
其它參數 :
-n requests     全部請求數
-c concurrency   併發數
-t timelimit     最傳等待迴應時間
-p postfile     POST 數據文件
-T content-type POST Content-type
-v verbosity    How much troubleshooting info to print
-w              Print out results in HTML tables
-i              Use HEAD instead of GET
-x attributes   String to insert as table attributes
-y attributes   String to insert as tr attributes
-z attributes   String to insert as td or th attributes
-C attribute     加入 cookie, eg. 'Apache=1234. (repeatable)
-H attribute     加入 http 頭 , eg. 'Accept-Encoding: gzip'
                Inserted after all normal header lines. (repeatable)
-A attribute    http 驗證 , 分隔傳遞用戶名及密碼
-P attribute    Add Basic Proxy Authentication, the attributes
                are a colon separated username and password.
-X proxy:port   代理服務器
-V               查看 ab 版本
-k              Use HTTP KeepAlive feature
-d              Do not show percentiles served table.
-S              Do not show confidence estimators and warnings.
-g filename     Output collected data to gnuplot format file.
-e filename     Output CSV file with percentages served
-h              Display usage information (this message)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章