一、安装
[root@node2 logs]# yum install httpd-tools 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 httpd-tools.x86_64.0.2.4.6-88.el7.centos 将被 安装 --> 解决依赖关系完成 依赖关系解决 =============================================================================================== Package 架构 版本 源 大小 =============================================================================================== 正在安装: httpd-tools x86_64 2.4.6-88.el7.centos base 90 k 事务概要 =============================================================================================== 安装 1 软件包 总下载量:90 k 安装大小:169 k Is this ok [y/d/N]: y Downloading packages: httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : httpd-tools-2.4.6-88.el7.centos.x86_64 1/1 验证中 : httpd-tools-2.4.6-88.el7.centos.x86_64 1/1 已安装: httpd-tools.x86_64 0:2.4.6-88.el7.centos 完毕!
二、使用
参数说明:
-n :请求总次数
-c:并发数
-k:是否开启长连接
-s:超时设置
例子:请求127.0.0.1,100次,并发10个
[root@node2 logs]# ab -n 100 -c 10 http://127.0.0.1/ 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/ Benchmarking 127.0.0.1 (be patient).....done Server Software: nginx/1.14.2 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: / Document Length: 612 bytes Concurrency Level: 10 Time taken for tests: 0.008 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 84500 bytes HTML transferred: 61200 bytes Requests per second: 12653.42 [#/sec] (mean) Time per request: 0.790 [ms] (mean) Time per request: 0.079 [ms] (mean, across all concurrent requests) Transfer rate: 10441.55 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 0 Processing: 0 1 0.1 1 1 Waiting: 0 1 0.1 1 1 Total: 0 1 0.1 1 1 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 1 95% 1 98% 1 99% 1 100% 1 (longest request)
以上输出结果中
Concurrency Level: 10 并发数
Time taken for tests: 0.008 seconds 总耗时
Complete requests: 100 成功请求数
Failed requests: 0 失败请求数
Requests per second: 12653.42 [#/sec] (mean) 即每秒的响应请求数,也即是最大吞吐能力(qps)总请求数/总耗时
Time per request: 0.790 [ms] (mean) 客户端发出请求到收到响应,单个请求所耗费的时间
Time per request: 0.079 [ms] (mean, across all concurrent requests) 表示服务端处理单个请求所耗费的时间
那么 0.790-0.079=0.711ms ,表示单个请求在网络传输中所耗费的时间,也就是说:客户端发出请求到收到响应的耗时=网络传输所耗费的时间+服务端处理请求所耗费的时间
Transfer rate: 10441.55 [Kbytes/sec] received :传输速率,当前为10M,可作为网络环境测试的重要参考