天天看点

用ab作压力测试

ab是Apache附带的压力测试工具,它非常容易使用。ab进行一切测试的本质都是基于HTTP,所以可以说它是对于web服务器软件的黑盒性能测试。

如下,查看版本信息

[root@localhost ~]# ab -V

This is ApacheBench, Version 2.3 <$Revision: 655654 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

[root@localhost ~]# ab -n1000 -c10 http://10.20.134.204/install.php

This is ApacheBench, Version 2.3 <$Revision: 655654 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 10.20.134.204 (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Completed 1000 requests

Finished 1000 requests

Server Software: Apache/2.2.17

Server Hostname: 10.20.134.204

Server Port: 80

Document Path: /install.php

Document Length: 22 bytes

Concurrency Level: 10

Time taken for tests: 0.193 seconds

Complete requests: 1000

Failed requests: 0

Write errors: 0

Total transferred: 239478 bytes

HTML transferred: 22044 bytes

Requests per second: 5186.35 [#/sec] (mean)

Time per request: 1.928 [ms] (mean)

Time per request: 0.193 [ms] (mean, across all concurrent requests)

Transfer rate: 1212.91 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 0 0.3 0 1

Processing: 1 1 0.2 2 4

Waiting: 0 1 0.3 1 4

Total: 1 2 0.4 2 4

ERROR: The median and mean for the processing time are more than twice the standard

deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)

50% 2

66% 2

75% 2

80% 2

90% 2

95% 2

98% 3

99% 3

100% 4 (longest request)

注意,在启动ab时,传入的3个参数:

-n1000 表示总请求数为1000

-c10 表示并发用户数为10

http://10.20.134.204/install.php 表示请求的目标url,这里只是举例子。

通过测试,可以看到服务器的吞吐率是5186.35 req/s,用户平均请求等待时间是1.928 ms