ab测试压力:
简介:
ab是由Appache提供的压力测试软件。安装appache服务器时会自带该压测软件。
如何使用 ?
ab -n 100 -c 100 http://www.baidu.com/
参数介绍:
n:表示:用于指定压力测试总共的执行次数 c:用于指定压力测试的并发数 url:目标压测地址 测试总次数为100,并发数为100(相当于100个用户同时访问,他们总共访问100次)
执行结果如下:
➜ ~ ab -n 100 -c 100 http://www.imooc.com/
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 www.imooc.com (be patient).....done
Server Software: openresty
Server Hostname: www.imooc.com
Server Port: 80
Document Path: / # 请求的url路径
Document Length: 182 bytes # 该文档共有182个字节
Concurrency Level: 100 # 请求的并发量
Time taken for tests: 0.728 seconds # 本次测试所耗费的时间
Complete requests: 100 # 完成100个请求
Failed requests: 0 # 处理请求失败次数为0
Non-2xx responses: 100
Total transferred: 37000 bytes # 100次请求总共传输数据37000字节(可见在网络传输中是有字节开销的)
HTML transferred: 18200 bytes # 100次请求所产生的数据有18200字节
Requests per second: 137.41 [#/sec] (mean) # 平均每秒处理137个请求
Time per request: 727.766 [ms] (mean)
Time per request: 7.278 [ms] (mean, across all concurrent requests)
Transfer rate: 49.65 [Kbytes/sec] received # 该值取决于网络环境,可以忽略
Connection Times (ms)
min mean[+/-sd] median max
Connect: 70 80 6.6 85 89
Processing: 64 102 94.5 78 495 # 表示服务器处理请求最快64毫秒,最慢495毫秒,平均102毫秒
Waiting: 64 101 93.7 77 485
Total: 134 183 96.4 160 583
Percentage of the requests served within a certain time (ms)
50% 160 # 表示50%的请求是在160毫秒完成的
66% 168 # 表示66%的请求是在168毫秒完成的
75% 175 # 表示75%的请求是在175毫秒完成的
80% 177
90% 179
95% 548
98% 573
99% 583 # 表示99%的请求是在583毫秒完成的
100% 583 (longest request)
➜ ~
主要参数介绍:
Requests per second: 137.41 [#/sec] (mean): 表示每秒可以处理137个请求
Time per request:727.766 [ms] (mean): 表示每次请求所产生的100个并发耗费的时长.(即:一个请求所响应的时长 * 并发数 ==》7.278 * 100)
Time per request:7.278 [ms] (mean, across all concurrent requests): 表示每个请求实际运行时间的平均值
当我们在做性能优化时,我们主要参考这几个参数:
在做性能测试时, Requests per second
的值要尽可能的大,也就是说并发量
要尽可能的大; Time per request
的值要尽可能的小,也就是说每个请求所花的时间要尽可能的小。同时也需要注意,当我们在做性能测试时,出现请求失败次数Failed requests
时,也就意味着到并发量极限了。
网友评论