压力测试工具-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.php
15 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 max
31 Connect: 0 8 3.9 10 13
32 Processing: 1222 2453 322.6 2520 3436
33 Waiting: 1175 2385 320.4 2452 3372
34 Total: 1222 2461 322.5 2528 3444
35  
36 Percentage of the requests served within a certain time (ms)
37 50% 2528     ## 50%的请求在25ms内返回
38 66% 2534     ## 60%的请求在26ms内返回
39 75% 2538
40 80% 2539
41 90% 2545
42 95% 2556
43 98% 3395
44 99% 3444
45 100% 3444 (longest request)

 

posted @ 2021-04-14 14:47  小嘉欣  阅读(148)  评论(0编辑  收藏  举报