1. 程式人生 > >用 Apache Bench 進行網站效能測試

用 Apache Bench 進行網站效能測試

Apache 有一個自帶的效能測試工具叫 ab (Apache Bench)。
用這個工具,只須指定同時連線數、請求數以及URL,即可測試網站或網站程式的效能。

通過 ab 命令傳送請求之後,可以得到每秒傳送位元組數、每秒處理請求數、每請求處理時間等統計資料。

若目標地址需使用者認證,可加 -A 引數。

ab 命令的常用引數:
-n 數值: 發起測試的請求數
-c 數值: 發起測試的同時連線數
-A 使用者名稱:密碼

需要注意的是,ab 只是對單一檔案的請求,訪問物件帶有影象檔案等情況下,則要具體情況具體分析。

下面是 ab 命令具體運用的兩個例項:

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd,

http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org
 
Benchmarking 192.168.1.2 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests

Server Software:        Apache/2.2.4
Server Hostname:        192.168.1.2
Server Port:            80

Document Path:          /index.html
Document Length:        44 bytes

Concurrency Level:      1000
Time taken for tests:   104.31250 seconds
Complete requests:      10000
Failed requests:        9

   (Connect: 9, Length: 0, Exceptions: 0)

Write errors:           0
Total transferred:      2920000 bytes
HTML transferred:       440000 bytes
Requests per second:    96.12 [#/sec] (mean)
Time per request:       10403.125 [ms] (mean)
Time per request:       10.403 [ms] (mean, across all concurrent requests)
Transfer rate:          27.41 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9  69.6      0    1203
Processing:   250 10083 2012.2  10609   12750
Waiting:       62 6590 2765.9   6687   11375
Total:        250 10093 2010.3  10625   12750

Percentage of the requests served within a certain time (ms)
  50%  10625
  66%  10875
  75%  11000
  80%  11031
  90%  11156
  95%  11359
  98%  11656
  99%  11828
  100%  12750 (longest request)

例項二:

C:/Documents and Settings/windone>ab -n 1000 -c 100 http://192.168.1.2:80/index.html
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.2 (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
Finished 1000 requests

Server Software:        Apache/2.2.4
Server Hostname:        192.168.1.2
Server Port:            80

Document Path:          /index.html
Document Length:        44 bytes

Concurrency Level:      100
Time taken for tests:   1.531250 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      292000 bytes
HTML transferred:       44000 bytes
Requests per second:    653.06 [#/sec] (mean)
Time per request:       153.125 [ms] (mean)
Time per request:       1.531 [ms] (mean, across all concurrent requests)
Transfer rate:          186.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   3.2      0      31
Processing:    78  141  21.0    140     203
Waiting:       62  139  21.0    140     187
Total:         78  141  21.0    140     203

Percentage of the requests served within a certain time (ms)
  50%    140
  66%    140
  75%    156
  80%    156
  90%    171
  95%    171
  98%    187
  99%    187
 100%    203 (longest request)