0%

Apache-AB性能测试工具

ApacheAB 官方Doc

Apache AB 性能测试工具,这是 apache 免费自带的 性能测试工具, 就在 apache bin目录下,他能模拟多个并发请求,主要用来测试你的 服务每秒能承受多少并发请求。

命令

ab -n 3000 -c 3000 http://www.test.com/
# -c 3000 每次发送3000 个请求
# -n 3000 共3000 个请求

ab -t 60 -c 100 http://www.test.com/
# -t 60 在 60s内发送请求,每次发送 100 个请求

带参数的的请求

ab -t 60 -c 100 -T "application/x-www-form-urlencoded" p p.txt http://www.test.com/
# application/x-www-form-urlencoded (默认值)
#  就是设置表单传输的编码,典型的post请求
# multipart/form-data
#  用来指定传输数据的特殊类型的,主要就是我们上传的非文本的内容,比如图片、mp3,文件等等
# text/plain
#  是纯文本传输的意思

发送 json 数据

ab -n 100000 -c 400 -p tempPara.txt -T application/json http://www.test.com/
# tempPara.txt
{"driverId": 17,"pageNo": 1,"pageSize": 20,"status": 1}

常用参数说明

参数说明

-A auth-username:password
# 对服务器提供BASIC认证信任。 
# 用户名和密码由一个:隔开,并以base64编码形式发送。 无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。

-c concurrency
#  一次产生的请求个数。默认是一次一个。

-n
# 一共请求多少次

-t timelimit 
# 测试所进行的最大秒数。
# 其内部隐含值是-n 50000。 它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-T 
# content-type POST数据所使用的Content-type头信息。

-p 
# POST-file包含了需要POST的数据的文件.

结果解析

This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.80.157 (be patient)
Completed 400 requests
Completed 800 requests
Completed 1200 requests
Completed 1600 requests
Completed 2000 requests
Completed 2400 requests
Completed 2800 requests
Completed 3200 requests
Completed 3600 requests
Completed 4000 requests
Finished 4000 requests

Server Software: Apache/2.2.15
Server Hostname: 192.168.80.157
Server Port: 80

Document Path: /phpinfo.php
#测试的页面
Document Length: 50797 bytes
#页面大小

Concurrency Level: 1000
#测试的并发数
Time taken for tests: 11.846 seconds
#整个测试持续的时间
Complete requests: 4000
#完成的请求数量
Failed requests: 0
#失败的请求数量
Write errors: 0
Total transferred: 204586997 bytes
#整个过程中的网络传输量
HTML transferred: 203479961 bytes
#整个过程中的HTML内容传输量
Requests per second: 337.67 [#/sec] (mean)
#最重要的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值
Time per request: 2961.449 [ms] (mean)
#最重要的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值
Time per request: 2.961 [ms] (mean, across all concurrent requests)
#每个连接请求实际运行时间的平均值
Transfer rate: 16866.07 [Kbytes/sec] received
#平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 483 1773.5 11 9052
Processing: 2 556 1459.1 255 11763
Waiting: 1 515 1459.8 220 11756
Total: 139 1039 2296.6 275 11843
#网络上消耗的时间的分解,各项数据的具体算法还不是很清楚

Percentage of the requests served within a certain time (ms)
50% 275
66% 298
75% 328
80% 373
90% 3260
95% 9075
98% 9267
99% 11713
100% 11843 (longest request)
#整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于275毫秒,66%的用户响应时间小于298毫秒,最大的响应时间小于11843毫秒。对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。

欢迎关注我的其它发布渠道