輕量級性能測試工具之ab

Apache Benchmark 簡稱ab,是apache自帶的性能測試工具。位於apache的bin目錄下。

首先:先安裝apache

通過cmd進入到bin目錄,(apache安裝在C:\www)如下:


C:\Users\marry>cd\

C:\>cd www

C:\www>cd bin

C:\www\bin>

ab的語法格式:ab [options] [http://]hostname[:port]/path

ab的參數較多,一般用 -n 和-c 就可以了

舉個簡單例子:C:\www\bin>ab -n 10 -c 10 http://user.qzone.qq.com/645272156/2

然後回車:如下

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 user.qzone.qq.com (be patient).....done


Server Software:        QZHTTP-2.38.18

//表示被測試的Web服務器軟件稱

Server Hostname:        user.qzone.qq.com

//表示請求的URL中的主機部分名稱

Server Port:            80                

//表示被測試的web服務器軟件的監聽端口


Document Path:          /645272156/2      

//表示請求的URL中的根絕對路徑

Document Length:        11997 bytes      

//表示HTTP響應數據的正文長度


Concurrency Level:      10              

//表示併發用戶數,這是我們設置的參數

Time taken for tests:   9.208 seconds    

//表示所有這些請求被處理完成所花費的總時間

Complete requests:      10              

//表示總請求數,這是我們設置的參數

Failed requests:        0                

//表示失敗的請求數

Write errors:           0                
Total transferred:      121806 bytes    

//整個場景中的網絡傳輸量
HTML transferred:       119970 bytes    

//整個場景中HTML的傳輸量
Requests per second:    1.09 [#/sec] (mean)  

//重點關注的吞吐率,

Time per request:       9208.161 [ms] (mean)  

//用戶平均請求等待時間,          

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

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

Transfer rate:          12.92 [Kbytes/sec] received

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


Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        3  634 1326.0      5    3289
Processing:    11 3737 3213.2   3091    9178
Waiting:        8 3442 2775.0   3027    6342
Total:         14 4372 3016.2   6316    9195

Percentage of the requests served within a certain time (ms)
 50%   6316
 66%   6338
 75%   6342
 80%   6346
 90%   9195
 95%   9195
 98%   9195
 99%   9195
100%   9195 (longest request) //整個場景最大響應時間不超過9195毫秒


下面介紹下ab的各參數含義:

-n requests     Number of requests to perform

//在測試會話中所執行的請求個數。默認時,僅執行一個請求(常用)

   -c concurrency Number of multiple requests to make

   //一次產生的請求個數。默認是一次一個。(常用)

   -t timelimit    Seconds to max. wait for responses

//測試所進行的最大秒數。其內部隱含值是-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而不是服務器的性能。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章