linux下压力测试工具ab的使用

时间:2023-03-08 21:19:58

一、安装

[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-.el7.centos 将被 安装
--> 解决依赖关系完成 依赖关系解决 ===============================================================================================
Package 架构 版本 源 大小
===============================================================================================
正在安装:
httpd-tools x86_64 2.4.-.el7.centos base k 事务概要
===============================================================================================
安装 软件包 总下载量: k
安装大小: k
Is this ok [y/d/N]: y
Downloading packages:
httpd-tools-2.4.-.el7.centos.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : httpd-tools-2.4.-.el7.centos.x86_64 /
验证中 : httpd-tools-2.4.-.el7.centos.x86_64 / 已安装:
httpd-tools.x86_64 :2.4.-.el7.centos 完毕!

二、使用

参数说明:

-n :请求总次数

-c:并发数

-k:是否开启长连接

-s:超时设置

例子:请求127.0.0.1,100次,并发10个

[root@node2 logs]# ab -n  -c  http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright 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.
Server Hostname: 127.0.0.1
Server Port: Document Path: /
Document Length: bytes Concurrency Level:
Time taken for tests: 0.008 seconds
Complete requests:
Failed requests:
Write errors:
Total transferred: bytes
HTML transferred: 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.1
Processing: 0.1
Waiting: 0.1
Total: 0.1 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (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,可作为网络环境测试的重要参考