輕量級性能測試工具之Apache Benchmark

AB(apache benchmark) 爲Apache自帶的性能測試工具在APACHE的bin目錄下。php

經過CMD進入apache的bin目錄下,本例以windows下的apache爲例。linux

C:\Program Files\Apache Software Foundation\Apache2.2\bin>apache

格式: ab [options] [http://]hostname[:port]/pathwindows

參數:服務器

   -n requests     Number of requests to performcookie

   //在測試會話中所執行的請求個數。默認時,僅執行一個請求網絡

   -c concurrency Number of multiple requests to make併發

   //一次產生的請求個數。默認是一次一個。jsp

   -t timelimit    Seconds to max. wait for responseside

   //測試所進行的最大秒數。其內部隱含值是-n 50000。它可使對服務器的測試限制在一個固定的總時間之內。默認時,沒有時間限制。

   -p postfile     File containing data to POST

  //包含了須要POST的數據的文件.

   -T content-type Content-type header for POSTing

   //POST數據所使用的Content-type頭信息。

   -v verbosity    How much troubleshooting info to print

  //設置顯示信息的詳細程度 - 4或更大值會顯示頭信息, 3或更大值能夠顯示響應代碼(404, 200等), 2或更大值能夠顯示警告和其餘信息。 -V 顯示版本號並退出。

   -w              Print out results in HTML tables

   //以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。

   -i              Use HEAD instead of GET

  // 執行HEAD請求,而不是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)

  //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數能夠重複。

   -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.

  //-P proxy-auth-username:password 對一箇中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。不管服務器是否須要(即, 是否發送了401認證需求代碼),此字符串都會被髮送。

   -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

   -h              Display usage information (this message)

  //-attributes 設置 屬性的字符串. 缺陷程序中有各類靜態聲明的固定長度的緩衝區。另外,對命令行參數、服務器的響應頭和其餘外部輸入的解析也很簡單,這可能會有不良後果。它沒有完整地實現HTTP/1.x; 僅接受某些'預想'的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即, 你多是在測試ab而不是服務器的性能。

參數不少,通常咱們用 -c 和 -n 參數就能夠了. 例如:

ab -c 1000 -n 1000 http://127.0.0.1/index.php

【linux下爲

./ab -c 1000 -n 1000 http://127.0.0.1/index.php】

這個表示同時處理1000個請求並運行1000次login.jsp文件.

ab -c 10 -n 10 http://10.14.132.35:8080/cs/user/login.jsp

window下爲

C:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 100 -n 100http://192.168.1.175:8080/cs/user/login.jsp

【linux下命令爲:

#/usr/local/apache2/bin/ab -c 1000 -n 1000 http://192.168.1.175:8080/cs/user/login.jsp】

This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0

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

Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/


Benchmarking 192.168.1.175 (be patient).....done


Server Software:        Apache-Coyote/1.1

//平臺apache 版本

Server Hostname:        192.168.1.175

//服務器主機名

Server Port:            8080

//服務器端口

Document Path:          /cs/user/login.jsp

//測試的頁面文檔

Document Length:        7536 bytes

//文檔大小

Concurrency Level:      100

//併發數

Time taken for tests:   13.125 seconds

//整個測試持續的時間

Complete requests:      100

//完成的請求數量

Failed requests:        0

//失敗的請求數量

Write errors:           0

//寫的錯誤數量

Total transferred:      788000 bytes

//整個場景中的網絡傳輸量

HTML transferred:       753600 bytes

//整個場景中的HTML內容傳輸量

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

//你們最關心的指標之一,至關於 LR 中的 每秒事務數 ,後面括號中的 mean 表示這是一個平均值

Time per request:       13125.000 [ms] (mean)

//你們最關心的指標之二,至關於 LR 中的 平均事務響應時間 ,後面括號中的 mean 表示這是一個平均值

Time per request:       131.250 [ms] (mean, across all concu

//每一個請求實際運行時間的平均值

Transfer rate:          58.63 [Kbytes/sec] received

//平均每秒網絡上的流量,能夠幫助排除是否存在網絡流量過大致使響應時間延長的問題


Connection Times (ms)

             min  mean[+/-sd] median   max

Connect:        0  102 886.7     16    8875

Processing:   188 9357 1702.7   9906   10156

Waiting:       16 9300 1954.0   9906   10156

Total:        188 9458 1562.2   9922   11281

//網絡上消耗的時間的分解

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

 50%   9922

 66%  10016

 75%  10047

 80%  10063

 90%  10125

 95%  10156

 98%  10156

 99%  11281

100%  11281 (longest request)

//整個場景中全部請求的響應狀況。在場景中每一個請求都有一個響應時間,其中50%的用戶響應時間小於9922 毫秒,最大的響應時間小於11281 毫秒


本文同步分享在 博客「51CTO_李曉鵬」(51CTO)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索