ab压力测试工具
ab是一种用于测试Apache超文本传输协议(HTTP)服务器的工具。apache自带ab工具,可以测试apache、IIs、tomcat、nginx、web等服务器
但是ab没有Jmeter、Loadrunner那样有各种场景设计、各种图形报告和监控,只需一个命令即可,有输出描述
可以简单的进行一些压力测试
一、Mac下自带apache
查看版本 apachectl -v
若是没有的话,可以执行命令安装:
sudo apt-get install apache2-utils
以请求百度为例:http://httpd.apache.org/docs/2.4/programs/ab.html 详细说明见官网
ab命令同时满足http及https的请求
常用请求参数:-n请求次数,-c并发数
以百度为例,执行语句及具体分析如下所示:
root@instance-lvzxy101:~# ab -c 10 -n 100 https://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
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,请求https端口80
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
//https端口协议
TLS Server Name: www.baidu.com
Document Path: /
//路径
Document Length: 227 bytes
//第一个成功返回的文档的字节大小
Concurrency Level: 10
//并发数!!!
Time taken for tests: 0.232 seconds
//从建立连接到最后接受完成总时间
Complete requests: 100
//总请求数成功的
Failed requests: 0
//失败的
Total transferred: 89300 bytes
//从服务器接收的字节总数
HTML transferred: 22700 bytes
//HTML接收字节数
Requests per second: 430.62 [#/sec] (mean)
————每秒请求数(总请求数/总时间)
Time per request: 23.222 [ms] (mean)
————用户平均请求等待时间=concurrency * timetaken * 1000 / done
参考Jmeter、LR中的平均响应时间
Time per request: 2.322 [ms] (mean, across all concurrent requests)
————服务器处理每个请求平均响应时间=timetaken * 1000 / done
Transfer rate: 375.53 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 9 12 6.9 12 79
Processing: 3 5 0.6 5 7
Waiting: 3 5 0.6 5 6
Total: 13 17 6.9 17 82
//网络连接情况
Percentage of the requests served within a certain time (ms)
50% 17 ## 50%的请求在17ms内返回
66% 18 ## 66%的请求在18ms内返回
75% 18
80% 18
90% 19
95% 19
98% 20
99% 82
100% 82 (longest request)
//整体响应时间的分布比