Apache Benchmark的简单使用

简介:

Apache Benchmark(ab)工具是常用的基准测试工具之一,是默认的Apache安装的一部分,独立于Apache服务器,这样能够在运行ab工具的同时使运行此工具的计算机上的web服务器处于非活动状态。能够通过模拟对特定的URL的任意数量请求来对Web服务器进行负载测试。ab工具提供以下信息:
1. 传输的总数据大小(以字节为单位);
2. Web服务器在模拟流量下每秒可以支持的请求总数;
3. 完成一个请求所花费的最长和最短时间(以毫秒为单位);
4. 可以运行对web文档的模拟请求以及指定时间内的请求
5. 打开Keep Alive时的请求。

安装

1. linux下安装Apache服务器的时候默认就安装了ab工具,Apache可以通过编译安装或者通过yum、apt-get方式安装,编译安装在前面的博文已经介绍,yum或apt-get方式在此略过。
2. windows下在安装Apache服务器后默认也安装了ab工具。在安装目录下的bin目录下有ab工具。

简单使用

ab工具的语法:
    ab [options] [ full path to web document ]

可以通过ab -h获取帮助

[root@lamp ~]# /usr/local/apache2/bin/ab -h
Usage: /usr/local/apache2/bin/ab [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)
[root@lamp ~]#

常用的参数主要有:n、c、t三个

  • n:要模拟的请求数
  • c:要模拟的并发请求数
  • t:执行模拟所需要的时间

模拟单个请求如下:

[root@lamp ~]# /usr/local/apache2/bin/ab -n 1 www.baidu.com/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.baidu.com (be patient).....done


Server Software:        BWS/1.1
Server Hostname:        www.baidu.com
Server Port:            80

Document Path:          /index.php
Document Length:        99971 bytes

Concurrency Level:      1
Time taken for tests:   0.156 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      100957 bytes
HTML transferred:       99971 bytes
Requests per second:    6.39 [#/sec] (mean)
Time per request:       156.401 [ms] (mean)
Time per request:       156.401 [ms] (mean, across all concurrent requests)
Transfer rate:          630.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       33   33   0.0     33      33
Processing:   123  123   0.0    123     123
Waiting:       37   37   0.0     37      37
Total:        156  156   0.0    156     156
[root@lamp ~]#

数据主要分为四个部分:

posted @ 2016-10-26 22:36  selfim  阅读(422)  评论(0)    收藏  举报