apache benchmark(ab) 进行压测

一、apache benchmark使用

PS D:\installed-software\Apache24\bin> ./ab.exe -help
Usage: D:\installed-software\Apache24\bin\ab.exe [options] [http://]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.
    -m method       Method name
    -h              Display usage information (this message)

    
二、进行压测


本次使用50并发、500次请求、自定义请求头token

PS D:\installed-software\Apache24\bin> ./ab.exe -c 50 -n 500 -H "token:666" http://127.0.0.1:8999/bench/bbbbbbbbb1
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        openresty/1.19.9.1
Server Hostname:        127.0.0.1
Server Port:            8999

Document Path:          /bench/bbbbbbbbb1
Document Length:        0 bytes

Concurrency Level:      50
Time taken for tests:   2.043 seconds
Complete requests:      500
Failed requests:        0
Non-2xx responses:      500
Total transferred:      60000 bytes
HTML transferred:       0 bytes
Requests per second:    244.74 [#/sec] (mean)
Time per request:       204.297 [ms] (mean)
Time per request:       4.086 [ms] (mean, across all concurrent requests)
Transfer rate:          28.68 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:   160  177  20.0    169     249
Waiting:      160  176  19.8    169     242
Total:        160  177  20.0    170     249

Percentage of the requests served within a certain time (ms)
  50%    170
  66%    174
  75%    178
  80%    179
  90%    230
  95%    232
  98%    236
  99%    237
 100%    249 (longest request)


 
三、结果分析
 
四、请求参数名词翻译

-n即requests,用于指定压力测试总共的执行次数。

-c即concurrency,用于指定压力测试的并发数。

-t即timelimit,等待响应的最大时间(单位:秒)。

-b即windowsize,TCP发送/接收的缓冲大小(单位:字节)。

-p即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。

-u即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。

-T即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。

-v即verbosity,指定打印帮助信息的冗余级别。

-w以HTML表格形式打印结果。

-i使用HEAD请求代替GET请求。

-x插入字符串作为table标签的属性。

-y插入字符串作为tr标签的属性。

-z插入字符串作为td标签的属性。

-C添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。

-H添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。

-A添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。

-X指定使用的代理服务器和端口号,例如:"126.10.10.3:88"。

-V打印版本号并退出。

-k使用HTTP的KeepAlive特性。

使用HTTP的KeepAlive特性。

-d不显示百分比。

-S不显示预估和警告信息。

-g输出结果信息到gnuplot格式的文件中。

-e输出结果信息到CSV格式的文件中。

-r指定接收到错误信息时不退出程序。

-h显示用法信息,其实就是ab -help。 

五、响应结果名词翻译


Server Software:    Web主機的作業系統與版本(若Web主機設定關閉此資訊則無);在此例中就是压力测试的对象nginx
Server Hostname:  Web主機的IP位址(Hostname)
Server Port:           Web主機的連接埠(Port)
Document Path:     測試網址的路徑部分
Document Length: 測試網頁回應的網頁大小
Concurrency Level: 同時進行壓力測試的人數
Time taken for tests: 本次壓力測試所花費的總秒數 ;此次压力测试花费的世间
Complete requests: 完成的要求數(Requests)
Failed requests:      失敗的要求數(Requests)
Write errors:           寫入失敗的數量
Total transferred:   本次壓力測試的總數據傳輸量(包括 HTTP Header 的資料也計算在內)
HTML transferred:  本次壓力測試的總數據傳輸量(僅計算回傳的 HTML 的資料)
Requests per second: 平均每秒可回應多少要求;是否可以认为是QPS
Time per request:       [ms] (mean)发起一组并发请求平均耗时耗时,这里对应-c 50的配置,理解为发起一轮并发50个请求,耗时204.297 [ms]
Time per request:       (mean, across all concurrent requests) 本次压测总时间除于总请求次数,等于平均时间 Time taken for tests 除于 Complete requests
Transfer rate:         從 ab 到 Web Server 之間的網路傳輸速度

参考文章
https://stackoverflow.com/questions/15730677/apache-bench-mean-vs-mean-across-all-concurrent-requests
https://www.bbsmax.com/A/A7zgk4PYz4/

你可能感兴趣的:(压测,开发工具)