ab test Apache Benchmark

Post:

ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/

Get:

ab -c 10 -n 1000 localhost/test
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
    -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是apache自带的压力测试工具。ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx、tomcat、IIS等。

一、Apache下载

Windows下载地址: http://www.apachehaus.com/cgi-bin/download.plx

根据系统版本选择

下载后,解压到C盘Apache 文件夹。

二、配置

修改Apache 端口:

如果是windows部署,多数情况下80端口已经被iis占用了,这时候需要修改conf/httpd.conf 找到listen 80 改为你要设置的端口,如: 8090。

三、Apache安装

以管理员身份运行cmd,命令行进入到Apache的bin目录,输入 httpd -k install 完成安装。

四、开始测试

在apache的bin目录下,cmd中输入:ab -n 1000 -c 1000 http://so.com/index
其中,-n 表示请求数,-c 表示并发数,index 为path,这是必要的,表示指定测试地址,不指定可能会报”ab: invalid url” 错误,可以实际测试一下。

其返回的结果集是有很多内容,我们选择关键的几个看看就大概知道我们的模块性能了
我比较关心的几个结果:
Concurrency Level: 1000
Time taken for tests: 1.190 seconds //处理1000个并发请求总共花了1.19秒
Complete requests: 1000 //完成处理的请求量
Failed requests: 0 //请求失败数
Write errors: 0
Non-2xx responses: 1000
Total transferred: 164000 bytes //总共传输了多少流量
HTML transferred: 0 bytes
Requests per second: 840.58 [#/sec] (mean) //平均一个请求花840.58毫秒 大家最关心的指标之一,相当于 LR 中的每秒事务数,后面括号中的 mean 表示这是一个平均值
Time per request: 1189.651 [ms] (mean) //大家最关心的指标之二,相当于 LR 中的平均事务响应时间,后面括号中的 mean 表示这是一个平均值
Time per request: 1.190 [ms] (mean, across all concurrent requests) //每个请求实际运行时间的平均值 ms是毫秒
Transfer rate: 134.62 [Kbytes/sec] received //传输速率 可以帮助排除是否存在网络流量过大导致响应时间延长的问题

LEAVE A COMMENT