压力测试工具-ab
压力测试工具-ab
一、原理
ab 命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。(ab命令对发出负载的计算机要求很低,它既不会占用很高的CPU,也不会占用很多内存,但却会给目标服务器造成巨大的负载。因此测试的时候也需要注意:一次上太多的负载,可能造成目标服务器资源耗完,严重时甚至导致死机)
二、安装
查看 ab 的安装位置:
which ab
不想安装 apache 但又想使用 ab 命令:
yum -y install httpd-tools #可以直接安装apache的工具包httpd-tools
查看ab是否安装成功:
ab -V
三、基础命令
四、指标解析
五、实际例子
1 [root@centos7 ~]#ab -c 10 -n 100 http://a.ilanni.com/index.php 2 -c 10表示并发用户数为10 3 -n 100表示请求总数为100 4 http://a.ilanni.com/index.php 表示请求的目标URL 5 这行表示同时处理100个请求并运行10次index.php文件。 6 7 [root@centos7 ~]#ab -c 10 -n 100 http://a.ilanni.com/index.php 8 Benchmarking 47.93.96.25 (be patient).....done 9 10 Server Software: Apache/2.4.29 ##apache版本11 Server Hostname: ip地址 ##请求的机子12 Server Port: 80 ##请求端口13 14 Document Path: index.php15 Document Length: 18483 bytes ##页面长度16 17 Concurrency Level: 10 ##并发数18 Time taken for tests: 25.343 seconds ##共使用了多少时间19 Complete requests: 100 ##请求数20 Failed requests: 11 ##失败请求21 (Connect: 0, Receive: 0, Length: 11, Exceptions: 0)22 Total transferred: 1873511 bytes ##总共传输字节数,包含http的头信息等23 HTML transferred: 1848311 bytes ##html字节数,实际的页面传递字节数24 Requests per second: 3.95 [#/sec] (mean) ##每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量25 Time per request: 2534.265 [ms] (mean) ##用户平均请求等待时间26 Time per request: 253.426 [ms] (mean, across all concurrent requests) ##服务器平均处理时间27 Transfer rate: 72.19 [Kbytes/sec] received ##每秒获取的数据长度28 29 Connection Times (ms)30 min mean[+/-sd] median max31 Connect: 0 8 3.9 10 1332 Processing: 1222 2453 322.6 2520 343633 Waiting: 1175 2385 320.4 2452 337234 Total: 1222 2461 322.5 2528 344435 36 Percentage of the requests served within a certain time (ms)37 50% 2528 ## 50%的请求在25ms内返回38 66% 2534 ## 60%的请求在26ms内返回39 75% 253840 80% 253941 90% 254542 95% 255643 98% 339544 99% 344445 100% 3444 (longest request)