[轉]web服務器壓力測試工具

http_load學習心得:php

測試網站每秒所能承受的平均訪問量(吞吐量)

http_load -parallel 5 -fetches 1000 urls.txt
這段命令行是同時使用5個進程,隨機訪問urls.txt中的網址列表,總共訪問1000次。運行以後的結果:web

1000 fetches, 5 max parallel, 6e+06 bytes, in 58.1026 seconds
6000 mean bytes/connection
17.2109 fetches/sec, 103266 bytes/sec
msecs/connect: 0.403263 mean, 68.603 max, 0.194 min
msecs/first-response: 284.133 mean, 5410.13 max, 55.735 min
HTTP response codes:
code 200 — 1000apache

從上面的運行結果來看,目標網站僅僅可以承受每秒17次訪問,不夠強壯。服務器

測試網站是否能承受住預期的訪問壓力(

http_load -rate 2 -seconds 300 urls.txt
在300秒內保持必定的頻率訪問目標url。cookie

注:併發

  • urls.txt保存要訪問的url列表,每行一個
  • 不要測試上線以後的網站,壓垮了可很差玩

例如:ide

1.http_load -parallel 5 -fetches 1000 urls.txt工具

2.http_load -rate 2 -seconds 300 urls.txtpost

3. http_load -p 30 -s 60   urllist.txt性能

4. http_load -parallel 50 -s 10 urls.txt
       這段命令行是同時使用50個進程,隨機訪問urls.txt中的網址列表,總共訪問10秒。

 

參數說明:

-parallel 簡寫-p :含義是併發的用戶進程數。
-fetches 簡寫-f :含義是總計的訪問次數
-rate    簡寫-r :含義是每秒的訪問頻率
-seconds簡寫-s :含義是總計的訪問時間

參數是能夠自由組合的,參數之間的選擇並無什麼限制。

urls.txt保存要訪問的url列表,

url 是你要訪問的網址名,參數能夠是單個的網址也能夠是包含網址的文件。文件格式是每行一個URL,URL最好超過50-100個測試效果比較好. 文件格式以下

http://iceskysl.1sters.com/?action=show&id=336
http://iceskysl.1sters.com/?action=show&id=335
http://iceskysl.1sters.com/?action=show&id=332
http://iceskysl.1sters.com/?action=show&id=32

參數瞭解了,咱們來運行一條命令, 來看看它的返回結果

命令:% ./http_load -rate 5 -seconds 10 urls
命令解釋: 執行一個持續時間爲10秒的測試,每秒的訪問頻率爲5次。

49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
5916 mean bytes/connection
4.89274 fetches/sec, 28945.5 bytes/sec (重要性能指標吞吐量)
msecs/connect
: 28.8932 mean, 44.243 max, 24.488 min(重要指標響應時間)
msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
HTTP response codes:
code 200 — 49

結果分析:
1.49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
說明在上面的測試中運行了49個請求,最大的併發進程數是2,總計傳輸的數據是289884bytes,運行的時間是10.0148秒
2.5916 mean bytes/connection
說明每一鏈接平均傳輸的數據量289884/49=5916
3.4.89274 fetches/sec, 28945.5 bytes/sec (吞吐量: 單位時間完成請求數)
說明每秒的響應請求爲4.89274,每秒傳遞的數據爲28945.5 bytes/sec
這個值得是根據 49 fetches / 10.0148 seconds 秒計算出來的
4.msecs/connect: 28.8932 mean, 44.243 max, 24.488 min (響應時間: 每次請求須要的時間, 平均, 最大, 最小)
說明每鏈接的平均響應時間是28.8932 msecs,最大的響應時間44.243 msecs,最小的響應時間24.488 msecs
5.msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
六、HTTP response codes: code 200 — 49

說明打開響應頁面的類型,若是403的類型過多,那可能要注意是否系統遇到了瓶頸。
特殊說明:這裏,咱們通常會關注到的指標是fetches/sec、msecs/connect
他們分別對應的經常使用性能指標參數

Qpt-每秒響應用戶數和response time,每鏈接響應用戶時間。
測試的結果主要也是看這兩個值。固然僅有這兩個指標並不能完成對性能的分析,咱們還須要對服務器的cpu、memory進行分析,才能得出結論

,另外,測試結果中主要的指標是 fetches/sec 這個選項,即服務器每秒可以響應的查詢次數,用這個指標來衡量性能。彷佛比 apache的ab準確率要高一些,也更有說服力一些。

 

 

 

http_load測試參數比較

6月 11th, 2008 Posted in  http_load < by Johnny Woo >

./http_load -parallel 200 -seconds 10 urls
按照固定時間來結束測試,這樣能夠比較相同時間內被測服務器的響應速度.
./http_load -parallel 200 -fetches 1000 urls
按照固定申請數來測試,這樣能夠比較相同訪問量下返回的響應速度.

雖然二者均可以獲取到服務器的響應速度
可是使用fetches更容易讓被測服務器收到壓力
因爲seconds控制測試時間,頗有可能在短期內測試客戶端並無發起足夠數量的請求
而服務端在收到足夠壓力以前,測試就已經結束了.
有一些狀況,諸如內存泄漏以及資源回收不利或者對後面的響應速度愈來愈慢等狀況
在這種測試條件下不容易發生
而使用fetchs,可以讓客戶端保證肯定請求數的所有處理.
使用時間做爲控制參數
會因爲測試人員不夠耐心而人爲將seconds參數設置太小
致使測試結果失去意義

因此,最後建議使用fetches做爲測試參數.用以做爲基準進行比較

 

 

http_load作測試時出現」byte count wrong」的錯誤,
若是httpd_load獲取到的頁面數據和上次不一致
則會報錯byte count wrong
若是是動態頁面,因爲返回數據內容不一樣.則此報錯能夠忽略

webbench

webbench是Linux下的一個網站壓力測試工具,最多能夠模擬3萬個併發鏈接去測試網站的負載能力。下載地址能夠到baidu google搜,我這裏給出一個
下載地址:http://cid-9601b7b7f2063d42.skydrive.live.com/self.aspx/Public/webbench-1.5.tar.gz
這個程序更小,解壓後不到50K,呵呵
安裝很是簡單
#tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install
會在當前目錄生成webbench可執行文件,直接可使用了

用法:

webbench -c 併發數 -t 運行測試時間 URL
如:
webbench -c 5000 -t 120 http://www.askwan.com



ab
ab是apache自帶的一款功能強大的測試工具
安裝了apache通常就自帶了,
用法能夠查看它的說明

引用
$ ./ab
./ab: wrong number of arguments
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
-p postfile File containing data to POST
-T content-type Content-type header for POSTing
-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
-h Display usage information (this message)



參數衆多,通常咱們用到的是-n 和-c
例如:
./ab -c 1000 -n 100 http://www.askwan.com/index.php這個表示同時處理1000個請求並運行100次index.php文件

相關文章
相關標籤/搜索