发布于 

简述ab压测的返回参数

说起压测,使用的比较多的命令就是ab。今天在研究nginx防刷的时候,用ab测试了防刷的效果,顺便写一篇ab返回数据释义帖。

对于ab的参数 我们最常用的就是 -n 和 -c:

参数名称 含义
-n 总共请求数
-c 每秒的并发数(此数不能大于n的次数)

假设我们执行一条ab命令如下所示:

1
 /usr/local/Cellar/nginx/1.8.1/ ab -n 5000 -c 101 http://127.0.0.1/index.html

得到的结果为:(请忽略较多的FailedRequest,这是限制访问导致的结果)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 /usr/local/Cellar/nginx/1.8.1/ ab -n 5000 -c 101 http://127.0.0.1/index.html
This is ApacheBench, Version 2.3 <$Revision: 1663405 $>
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 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software: nginx/1.8.1
Server Hostname: 127.0.0.1
Server Port: 80

Document Path: /index.html
Document Length: 612 bytes

Concurrency Level: 101
Time taken for tests: 4.196 seconds
Complete requests: 5000
Failed requests: 2907
(Connect: 0, Receive: 0, Length: 2907, Exceptions: 0)
Non-2xx responses: 2907
Total transferred: 3888602 bytes
HTML transferred: 2841975 bytes
Requests per second: 1191.64 [#/sec] (mean)
Time per request: 84.757 [ms] (mean)
Time per request: 0.839 [ms] (mean, across all concurrent requests)
Transfer rate: 905.04 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.9 0 9
Processing: 0 82 97.7 1 225
Waiting: 0 82 97.7 1 225
Total: 0 83 97.7 1 225

Percentage of the requests served within a certain time (ms)
50% 1
66% 200
75% 201
80% 201
90% 201
95% 201
98% 202
99% 202
100% 225 (longest request)

参数释义:

参数名称 含义 备注
Server Software Web服务器及其版本 nginx/1.8.1
Server Hostname 主机地址 127.0.0.1
Server Port Web服务器监听端口号 80
Document Path 文档(资源)地址 /index.html
Concurrency Level 并发数 101
Time taken for tests 本次压测使用的总时间 4.196 seconds
Complete requests 发起的总请求数 5000
Failed requests 失败的请求数 2907
Non-2xx responses 非2xx状态请求数 2907,非2xx并不代表请求一定是失败的
Total transferred 传输的总字节数大小 3888602 bytes,网络中传输的总字节数
HTML transferred 传输的总文档字节数大小 2841975 bytes,其中是不包含HTTP的Header数据的
Requests per second 每秒处理的请求数 1263.02 [#/sec] (mean)表示每秒评平均处理1263.02个请求,是总时间除以总请求数的值,也就是我们平常说的QPS
Time per request 每个请求花费的平均时间 84.757 [ms] (mean) 0.839 [ms] (mean, across all concurrent requests)第一个值=并发数(101)*总时间(4.196)/总请求数(5000):84.757=(101*4.196/5000);第二个值=总时间/总请求数:(4.196/5000)*1000

Connection Times 参数释义:

  • 竖栏:
参数名称 含义 备注
Connect 创建TCP连接到服务器或者代理服务器所花费的时间 通常我们习惯设置Web服务器的Connection:keep-alive,防止重复建立连接,减少请求时间
Processing 写入缓冲区消耗+链路消耗+服务端消耗 -
Waiting 写入缓冲区消耗+链路消耗+服务端消耗+读取数据消耗 -
Total 总花费时间 -
  • 横栏:
参数名称 含义
min 最小值
mean 平均值
median 中位数
max 最大值

备注:

这些竖栏参数的含义和Chrome的Network里的Time指数大致是一致的,其中

  • Queuing是指闭塞时间,也就是等待以下情况的时间:

    • 通常一个浏览器对一个域名发起请求的时候有最大TCP连接数,这个就是请求进程等待可用的TCP连接时被阻塞的等待时间,chrome在 http1.x 里是允许最多建立6个TCP连接
    • 渲染引擎为了优先展示某些特定资源(如scripts、styles)而推迟其他资源的加载
    • 写入硬盘缓冲区的等待时间(内核中有读/写缓冲区,我们调用socket进行write,这个函数执行完数据并不一定已经发送到服务端,而是从用户空间拷贝到了”写缓冲区”,当发送完毕后再从缓冲区删除)
  • Proxy Negotiation代理协商时间

  • Blocked/Stalled发送请求前的等待时间 = Queuing+ Proxy Negotiation

  • DNS LookupDNS查找时间

  • Initial Connection / Connecting连接建立时间(包含TCP连接的握手、重试以及SSL的协商时间)

  • SSL完成SSL握手的时间

  • Request Sent / Sending请求发送时间(从请求发送的第一个字节时间到最后一个字节完成发送花费的时间)

  • Waiting (TTFB)Time To First Byte,通常理解为服务端的处理时间,Response的第一个字节的返回时间

  • Content Download / DownloadingResponse下载时间

  • Cache Read缓存读取,是花费在从浏览器缓存中读取内容或者304响应的时间。

参考资料:

  1. apache ab 输出结果详细解析(源码分析)

  2. chrome的timeline的问题?

  3. Google Developer-Understanding Resource Timing-New

  4. Google Developer-Understanding Resource Timing-Old

  5. 关于请求被挂起页面加载缓慢问题的追查