linux使用ab程序及对网页做压力测试,ab压力测试


ab其实是一个小程序,
用来对网页做并发测试,
你在linux上安装apache后,
就能使用了。

下面的内容,
我们假设你按照上一篇文章的方法,
安装了apache,
并且添加把apache的bin目录添加到了PATH。

ab压力测试

一、 使用ab压力测试
模拟100个并发用户,对一个页面发送 1000 个请求

ab -n 1000 -c 100 https://211.qinziheng.com/
ab -n 1000 -c 100 https://www.qinziheng.com/
ab -n 1000 -c 100 https://localhost/

-n 是请求数量
-c 是并发数量

更多参数可以使用下面的方式得到

ab --help

需要注意的是,
一定是对某个具体的页面测试,
如果你是写目录,
会得不到相关数据,

ab -n 1000 -c 100 https://www.qinziheng.com
ab -n 1000 -c 100 https://localhost

上面的ab测试是无法获取到测试数据

二、 ab测试数据
如果正常,
你的ab测试完后,
会得到类似下面的数据信息:

Server Software: Apache/2.4.29
Server Hostname: localhost
Server Port: 80

Document Path: /
Document Length: 45 bytes

Concurrency Level: 100
Time taken for tests: 0.202 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 289000 bytes
HTML transferred: 45000 bytes
Requests per second: 4949.37 [#/sec] (mean)
Time per request: 20.205 [ms] (mean)
Time per request: 0.202 [ms] (mean, across all concurrent requests)
Transfer rate: 1396.84 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 2.1 2 13
Processing: 1 16 8.6 16 55
Waiting: 1 14 8.1 14 54
Total: 5 19 8.2 18 58

Percentage of the requests served within a certain time (ms)
50% 18
66% 21
75% 23
80% 24
90% 30
95% 33
98% 42
99% 43
100% 58 (longest request)

其中
Document Length: 45 bytes
表示请求文本大小

Requests per second: 4949.37 [#/sec] (mean)
表示每秒Requests次数

相关内容