Apache Bench测试

455 阅读2分钟
Apache Bench是Apache附带的一个工具,也叫ab压力测试,总体来说,ab工具小巧简单,上手学习较快,可以提供需要的基本性能指标;但是缺点就是没有图形化结果,不能监控。


ab安装

linux环境:

yum -y install httpd-tools

ab常用参数

-n :总共的请求执行数,缺省是1;

-c: 并发数,缺省是1;

-t:测试所进行的总时间,秒为单位,缺省50000s

-p:POST时的数据文件

-w: 以HTML表的格式输出结果

测试:

ab -c 100 -n 10000 http://www.baidu.com/1

结果:

Server Software:        Apache
Server Hostname:        www.baidu.com  #请求的URL主机名
Server Port:            80             #请求端口

Document Path:          /1             #请求路径
Document Length:        222 bytes      #HTTP响应数据的正文长度

Concurrency Level:      100            #并发用户数,这是我们设置的参数之一
Time taken for tests:   5.157 seconds    #所有这些请求被处理完成所花费的总时间 单位秒
Complete requests:      10000            #总请求数量,这是我们设置的参数之一
Failed requests:        1                #表示失败的请求数量
   (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Write errors:           0
Non-2xx responses:      10000
Total transferred:      4839692 bytes  #所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred:       2219778 bytes   #所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second:    1939.22 [#/sec] (mean)  #吞吐量,计算公式:Complete requests/Time taken for tests  总请求数/处理完成这些请求数所花费的时间
Time per request:       51.567 [ms] (mean)   #用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)。处理完成所有请求数所花费的时间/(总请求数/并发用户数)
Time per request:       0.516 [ms] (mean, across all concurrent requests)  #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
Transfer rate:          916.53 [Kbytes/sec] received  #表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        5   27 150.1      9    3018
Processing:     7   16  53.0     10    1679
Waiting:        7   16  52.9     10    1678
Total:         13   43 159.4     19    3035

Percentage of the requests served within a certain time (ms)
  50%     19    #50%的请求在19ms内返回  66%     20
  75%     21
  80%     22
  90%     23
  95%     35
  98%    233        #98%的请求在233ms内返回
  99%   1019
 100%   3035 (longest request)