ab全称为:apache bench
AB是Apache的超文本传输协议(HTTP)的性能测试工具。其设计意图是描绘当前所安装的的Apache的执行性能,主要是显示你安装的Apache的每秒可以处理多少个请求。它不仅可以对阿帕奇服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试。比如nginx的,tomcat的,IIS等。
但是ab没有Jmeter、Loadrunner那样有各种场景设计、各种图形报告和监控,只需一个命令即可,有输出描述
可以简单的进行一些压力测试
安装使用
ab工具是
apache
的一个命令,如果我们的服务器上没有安装apache
也可以使用ab工具的
打开终端输入以下命令, 这里我使用的是Centos 7的系统
yum -y install httpd-tools
- ab命令同时满足
http
及https
的请求 - 常用请求参数:
-n
要请求的次数,-c
并发数
ab -n 100 -c 10 https://www.baidu.com/
请求结果如下
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
#-----------^---------------以上是apache的版本信息
Benchmarking www.baidu.com (be patient).....done
Server Software: BWS/1.1 #请求返回header类型,可能是nginx、apache、IIs等
Server Hostname: www.baidu.com #请求的ip或者域名
Server Port: 443 #请求端口号,当前请求为https所以端口为443,请求http端口80
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 # https端口所用协议
Document Path: / #请求路径
Document Length: 227 bytes #第一次成功返回的文档的字节大小
Concurrency Level: 10 # 请求并发数
Time taken for tests: 0.730 seconds #从建立连接到最后完成的总时间
Complete requests: 100 #总请求数成功的
Failed requests: 0 #总请求数失败的
Write errors: 0 #错误的
Total transferred: 89300 bytes #从服务器接收的字节总数
HTML transferred: 22700 bytes #HTML接收字节数
#--------------------------------------------------------------------------主要看这一部分的数据--------v-----------
Requests per second: 136.98 [#/sec] (mean) 每秒请求次数 =(总请求次数 / 总时间)
Time per request: 73.002 [ms] (mean) #用户平均请求等待时间
Time per request: 7.300 [ms] (mean, across all concurrent requests) #服务器处理每个请求平均响应时间
Transfer rate: 119.46 [Kbytes/sec] received
#---------------------------------------------------------------------------------------------^------------------
Connection Times (ms) # 以下为网络连接情况------------v----------
min mean[+/-sd] median max
Connect: 29 47 19.4 45 208
Processing: 12 16 2.4 16 21
Waiting: 12 16 2.4 16 21
Total: 42 63 20.0 61 222
Percentage of the requests served within a certain time (ms) # 整体响应时间的分布比------v--------
50% 61
66% 64
75% 72
80% 73
90% 75
95% 77
98% 128
99% 222
100% 222 (longest request)