Apache ab壓力測試筆記

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 at a time   //表示併發數
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -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.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -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
                    (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

基本命令:

ab -n 100 -c 10 http://www.baidu.com

名詞解釋:

 Concurrency Level: 100    //併發請求數

 Time taken for tests: 50.872 seconds  //整個測試持續的時間

 Complete requests: 1000   //完成的請求數

 Failed requests: 0  //失敗的請求數

 Total transferred: 13701482 bytes  //整個場景中的網絡傳輸量

 HTML transferred: 13197000 bytes  //整個場景中的HTML內容傳輸量

Requests per second: 19.66 [#/sec] (mean) //吞吐率,大家最關心的指標之一,相當於 LR 中的每秒事務數,後面括號中的 mean 表示這是一個平均值

Time per request: 5087.180 [ms] (mean) //用戶平均請求等待時間,大家最關心的指標之二,相當於 LR 中的平均事務響應時間,後面括號中的 mean 表示這是一個平均值
Time per request: 50.872 [ms] (mean, across all concurrent requests) //服務器平均請求處理時間,大家最關心的指標之三

Transfer rate: 263.02 [Kbytes/sec] received    //平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題

 

模擬登陸步驟

  1. 先用賬戶和密碼登錄後,用開發者工具找到標識這個會話的Cookie值(Session ID)記下來
  2. 如果只用到一個Cookie,那麼只需鍵入命令:
    ab -n 100 -C key=value http://test.com/

    如果需要多個Cookie,就直接設Header:
    ab -n 100 -H “Cookie: Key1=Value1; Key2=Value2” http://test.com/

 

 

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