Apache ab压测工具使用

ab是一种用于测试Apache超文本传输协议(HTTP)服务器的工具。apache自带ab工具,可以测试
apache、IIs、tomcat、nginx等服务器

linux 安装

yum -y install httpd-tools

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.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key

直接看操作手册可能有点上头,我给大家翻译了一些

参数信息 变量 说明
-n request 请求总数
-c concurrency 并发数
-t timelimit 用于基准测试的最长时间
-s timeout 请求超时时间,默认30s
-b windowsize TCP发送/接收缓冲区的大小,以字节为单位
-B address 请求地址
-p postfile post请求体(是一个文件)
-u putfile put请求体(是一个文件)
-T contentType post/put请求的content-type。eg:'application/json';'applicationx-www-form-urlencoded'
-v verbosity 设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
-w 在HTML表格中打印结果
-i 执行HEAD请求,而不是GET请求
-x attributes 要作为表属性插入的字符串
-y attributes 作为tr属性插入的字符串
-z attributes 作为td属性插入的字符串
-C attributes 添加cookie eg. 'Apache=1234'
-H attributes 添加Header eg.'Accept-Encoding: gzip'
-k 使用HTTP KeepAlive功能
-g filename 将收集到的数据输出到gnuplot格式文件。
-e filename 结果输出到CSV文件
-r 发生socker错误时不退出
-h 不展示用例信息

压测GET请求

请求地址:http://127.0.0.1:8074/raindrop/snowflake
并发数 100
请求总数 1000

ab -c 100 -n 1000 http://127.0.0.1:8074/raindrop/snowflake

结果

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8074

Document Path:          /raindrop/snowflake
Document Length:        80 bytes

Concurrency Level:      100
Time taken for tests:   0.465 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      199000 bytes
HTML transferred:       80000 bytes
Requests per second:    2152.84 [#/sec] (mean)
Time per request:       46.450 [ms] (mean)
Time per request:       0.465 [ms] (mean, across all concurrent requests)
Transfer rate:          418.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   3.2      1      17
Processing:     3   43  62.2     23     336
Waiting:        3   36  58.7     18     324
Total:          7   45  61.8     27     337

Percentage of the requests served within a certain time (ms)
  50%     27
  66%     29
  75%     34
  80%     36
  90%    212
  95%    222
  98%    233
  99%    247
 100%    337 (longest request)

通过结果可以看出压测的一些信息,比如最小链接时间,最长链接时间,请求响应的信息等。

发送POST请求

请求地址:https://www.test.com/user/secret/listPage
并发数:100
请求总数:1000
content-type:application/json
请求体:{}

POST请求需要将请求体放到指定的文件中,新建一个post.txt文件,文件内容是请求体。

 ab -c 100 -n 1000 -p post.txt -T 'application/json' https://www.test.com/user/secret/listPage

压测结果

Server Software:        nginx/1.16.1
Server Hostname:        www.test.com
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
Server Temp Key:        ECDH P-256 256 bits
TLS Server Name:        www.zhengoole.com

Document Path:          /user/secret/listPage
Document Length:        153 bytes

Concurrency Level:      100
Time taken for tests:   16.345 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      371000 bytes
Total body sent:        157000
HTML transferred:       153000 bytes
Requests per second:    61.18 [#/sec] (mean)
Time per request:       1634.501 [ms] (mean)
Time per request:       16.345 [ms] (mean, across all concurrent requests)
Transfer rate:          22.17 [Kbytes/sec] received
                        9.38 kb/s sent
                        31.55 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      165 1167 1338.3    490    6001
Processing:    58  252 324.6    101    1489
Waiting:       58  250 324.0     99    1488
Total:        226 1419 1324.1    877    6113

Percentage of the requests served within a certain time (ms)
  50%    877
  66%   1566
  75%   1934
  80%   2073
  90%   3105
  95%   4926
  98%   5090
  99%   6028
 100%   6113 (longest request)

你可能感兴趣的:(Apache ab压测工具使用)