網站性能測試工具Apache Benchmark

網站性能測試工具Apache Benchmark

  • 收錄時間:2017-06-02
  • 閱讀:79次
  • 分享:
編輯評級
4

詳細介紹

http://httpd.apache.org/docs/2.0/programs/ab.html

在網站開發中,有時候需要對網站進行性能測試,知道網站在一定的并發訪問下的響應時間等情況,這里介紹Apache的一個工具,Apache Benchmark,可以比較方便的對網站做一些性能測試

簡介:

Apache Benchmark是Apache的http服務器httpd的附帶軟件,到http://httpd.apache.org/下載httpd服務器,安裝完成后,會在bin目錄下找到ab.exe,

運行ab –h,可以看到ab的完整說明如下

Usage: ab [options] [http://]hostname[:port]/path

Options are:

-n requests     Number of requests to perform

-c concurrency  Number of multiple requests to make

-t timelimit    Seconds to max. wait for responses

-b windowsize   Size of TCP send/receive buffer, in bytes

-p postfile     File containing data to POST. Remember also to set -T

-u putfile      File containing data to PUT. Remember also to set -T

-T content-type Content-type header for POSTing, eg.

‘application/x-www-form-urlencoded’

Default is ‘text/plain’

-v verbosity    How much troubleshooting info to print

-w              Print out results in HTML tables

-i              Use HEAD instead of GET

-x attributes   String to insert as table attributes

-y attributes   String to insert as tr attributes

-z attributes   String to insert as td or th attributes

-C attribute    Add cookie, eg. ‘Apache=1234. (repeatable)

-H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’

Inserted after all normal header lines. (repeatable)

-A attribute    Add Basic WWW Authentication, the attributes

are a colon separated username and password.

-P attribute    Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

-X proxy:port   Proxyserver and port number to use

-V              Print version number and exit

-k              Use HTTP KeepAlive feature

-d              Do not show percentiles served table.

-S              Do not show confidence estimators and warnings.

-g filename     Output collected data to gnuplot format file.

-e filename     Output CSV file with percentages served

-r              Don’t exit on socket receive errors.

-h              Display usage information (this message)

對于最基本的使用,假設本地有一個http://localhost/phptest.php顯示phpinfo,可以使用-c和-n參數,

運行如下命令測試當并發請求是10個,總共請求是100個的時候的性能數據,

ab -n 1000 -c 100 http://localhost/phptest.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 localhost (be patient)

Server Software:        Apache/2.2.14

Server Hostname:        localhost

Server Port:            80

Document Path:          /phptest.php

Document Length:        43931 bytes

Concurrency Level:      100

Time taken for tests:   7.563 seconds

Complete requests:      1000

Failed requests:        0

Write errors:           0

Total transferred:      44099000 bytes

HTML transferred:       43931000 bytes

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

Time per request:       756.250 [ms] (mean)

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

Transfer rate:          5694.60 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0    4  16.3      0     469

Processing:   203  706 247.4    656    1547

Waiting:      172  381 168.9    328    1125

Total:        203  710 248.1    656    1563

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

50%    656

66%    688

75%    688

80%    719

90%   1172

95%   1375

98%   1422

99%   1453

100%   1563 (longest request)

結果比較簡單,重點是紅色部分,意思是說在100個并發請求下,完成1000個請求,總共需要7.5秒,1000個請求全部完成,沒有失??;其中,平均用時710毫秒,標準差是248毫秒,中位數【就是50%請求時間】是656毫秒,90%請求時間是1172毫秒,就是1.172秒,最慢的請求用了1.563秒;

基本上,可以通過調整這-n和-c兩個參數來確定系統可以支撐的并發量。

另外,如果是動態頁面,比如需要登陸以后才能看到的頁面,可以先在Firefox中打開頁面,然后通過firebug查看session相關的Cookie,然后使用-C的參數指定,就可以假定用戶登陸了:

ab -c 100 -n 1000 -C JSESSIONID=1CBDB188AB4C901C2C3DC2C5BAEA1F47 http://localhost:9080/myapp

當然,ab還有很多缺陷,比如不能模擬多種不同類型的用戶做不同的操作,不能模擬實際的用戶思考時間等,缺乏圖形化的工具顯示結果等等。其他有些工具克服了這些缺陷。

最新收錄

湖北体彩十一选五玩法 河南今天11选5走势图 腾讯分分彩0369规律计划方法 11选5任一一期一计划 网上彩票销售平台 十二选五辽宁一定牛 江西多乐彩11选5一定牛 湖北福彩快3走势图带连线 股城模拟炒股网页 聚宏鑫配资 河南快3走势图