当前位置: 移动技术网 > IT编程>开发语言>Java > 压力测试工具Apache Bench实现原理及用法解析

压力测试工具Apache Bench实现原理及用法解析

2020年08月06日  | 移动技术网IT编程  | 我要评论

1:吞吐率(requests per second)

服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。

记住:吞吐率是基于并发用户数的。这句话代表了两个含义,1:吞吐率和并发用户数相关;2:不同的并发用户数下,吞吐率一般是不同的。

计算公式:总请求数 / 处理完成这些请求数所花费的时间,即

request per second = complete requests / time taken for tests

2:并发连接数(the number of concurrent connections)

并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。

3:并发用户数(the number of concurrent users,concurrency level)

要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。在http/1.1下,ie7支持两个并发连接,ie8支持6个并发连接,firefox3支持4个并发连接,所以相应的,我们的并发用户数就得除以这个基数。

4:用户平均请求等待时间(time per request)

计算公式:处理完成所有请求数所花费的时间/ (总请求数 / 并发用户数),即

time per request = time taken for tests /( complete requests / concurrency level)

5:服务器平均请求等待时间(time per request: across all concurrent requests)

计算公式:处理完成所有请求数所花费的时间 / 总请求数,即

time taken for / testscomplete requests

可以看到,它是吞吐率的倒数。

同时,它也=用户平均请求等待时间/并发用户数,即

time per request / concurrency level

官网下载地址:

下载后解压,用cmd进入当前的项目解压目录:

然后进入shell命令的执行界面(进入到bin目录下):

测试命令:

./ab -n 100 -c 10 http://localhost:8085/linewell/test1/pass/testapachebench.do

-n标识请求的个数,-c表示一次最多几次请求同时发出。

因为本人java测试,如果-c设置为1,java后端controller延时一秒, 是会一个一个处理的,基本需要100次处理。如果-c为10,是会一次性处理10个。

输出:

this is apachebench, version 2.3 <$revision: 1843412 $>
copyright 1996 adam twiss, zeus technology ltd, http://www.zeustech.net/
licensed to the apache software foundation, http://www.apache.org/

benchmarking localhost (be patient).....done


server software:
server hostname:    localhost
server port:      8085

document path:     /linewell/test1/pass/testapachebench.do
document length:    0 bytes

concurrency level:   10
time taken for tests:  0.077 seconds
complete requests:   100
failed requests:    0
non-2xx responses:   100
total transferred:   9200 bytes
html transferred:    0 bytes
requests per second:  1299.09 [#/sec] (mean)
time per request:    7.698 [ms] (mean)
time per request:    0.770 [ms] (mean, across all concurrent requests)
transfer rate:     116.72 [kbytes/sec] received

connection times (ms)
       min mean[+/-sd] median  max
connect:    0  0  0.3   0    1
processing:   1  5  3.4   5   27
waiting:    1  4  3.1   4   26
total:     2  5  3.4   5   27

percentage of the requests served within a certain time (ms)
 50%   5
 66%   6
 75%   7
 80%   7
 90%   9
 95%   11
 98%   11
 99%   27
 100%   27 (longest request)

输出结果解析:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网