天天看點

用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