用 Apache Bench 进行网站性能测试

 

Apache 有一个自带的性能测试工具叫 ab (Apache Bench)。
用这个工具,只须指定同时连接数、请求数以及URL,即可测试网站或网站程序的性能。

通过 ab 命令发送请求之后,可以得到每秒传送字节数、每秒处理请求数、每请求处理时间等统计数据。

举个例子,要得到同时连接数为 100、请求数达 1000,访问 http://localhost/index.html 的性能测试数据,命令

格式如下:
ab -n 10000 -c 1000 http://localhost/index.html

若目标地址需用户认证,可加 -A 参数。

ab 命令的常用参数:
-n 数值: 发起测试的请求数
-c 数值: 发起测试的同时连接数
-A 用户名:密码

需要注意的是,ab 只是对单一文件的请求,访问对象带有图像文件等情况下,则要具体情况具体分析。

下面是 ab 命令具体运用的两个实例:

实例一:
ab -n 10000 -c 1000 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 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)

 

你可能感兴趣的:(apache,server,测试,processing,Path,测试工具)