ubuntu中使用ab壓測

  • 安裝
apt-get update
apt-get install apache2-utils -y
apt-get install man -y
man ab  #查看ab語法
ab [ -A auth-username:password ] [ -b windowsize ] [ -B local-address ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -E client-certificate file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -l ] [ -m HTTP-method ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s timeout ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -u PUT-file ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path
  • 示例
ab -n 5 -c 1 -p data.json -T application/json -H 'Authorization: Token abcd1234' http://dmcv.service.dl.bdp.com.cn/car

data.json中內容如下:
{"service_type":"test", "service_key":"test"}
  • 結果,各字段的詳細意義可參考該文章
Server Software:        nginx/1.15.8
Server Hostname:        dmcv.service.dl.bdp.com.cn/car
Server Port:            80

Document Path:          /car
Document Length:        102 bytes

Concurrency Level:      1                #併發數,對應命令中 -c字段值
Time taken for tests:   0.051 seconds    #測試總時間
Complete requests:      5                #成功請求數
Failed requests:        1                #錯誤請求數
    (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Total transferred:      1550 bytes       #總的網絡傳輸量
HTML transferred:       510 bytes        #html內容傳輸量
Requests per second:    98.18 [#/sec] (mean)  #平均吞吐率
Time per request:       10.185 [ms] (mean)    #用戶平均請求等待時間
Time per request:       10.185 [ms] (mean, across all concurrent requests)  #服務端平均處理時間
Transfer rate:          29.72 [Kbytes/sec] received  #網絡流量,排查流量大小造成的延時

Connection Times (ms)                     #網絡消耗時間
              min  mean[+/-sd] median   max
Connect:        1    2   1.8      1       5
Processing:     5    8   6.3      5      19
Waiting:        5    8   6.4      5      19
Total:          7   10   6.1      9      21
原因:返回結果的長度不同導致Failed requests值不爲0
The apache benchmarking tool (ab) assumes that length of response content will be the same during entire test. It stores the content length of the first response. If any of further responses have different content length, they result in "length failures"

解決方法:
命令行中加 -l 即可

參考文獻:

  1. Install Apache Bench – Ubuntu 14.04

  2. ab工具語法

  3. 超實用壓力測試工具-ab工具

  4. Load Testing with AB … fake failed requests (length)

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