tsung文檔說明

1、默認編碼:utf-8,你能夠根據須要進行修改,如
<?xml version=」1.0″ encoding=」ISO-8859-1″?>
2、xml文件的結構
先總體瞭解xml文件的結構,它是由下面這些標籤構成
2.1頂級標籤<tsung>
2.2客戶端標籤<clients>
2.3服務端標籤<servers>
2.4監控標籤<monitor>
2.5負載標籤<load>
2.6選項標籤<options>
2.7過程標籤<sessions>
3、頂級標籤:
1.1頂級標籤是tsung,如
<?xml version=」1.0″?>
<!DOCTYPE tsung SYSTEM 「/usr/share/tsung/tsung-1.0.dtd」 [] >
<tsung loglevel=」info」>

</tsung>
1.2參數:
1.2.1:dumptraffic
true:全部的通訊都會被記錄,注:這會大大下降tsung速度,通常是用於調試
light:只轉儲前44字節
1.2.2:loglevel:
emergency
critical
error
warning(推薦)
notice (默認)
info
debug(須要察看詳細信息時,注:使用這個屬性時要用make debug從新編譯tsung)
3、客戶端標籤與服務端標籤(這兩個有關聯,需對照理解)
3.1簡單設置:
<clients>
<client host=」localhost」 use_controller_vm=」true」/>
</clients>
<servers>
<server host=」127.0.0.1″ port=」80″ type=」tcp」></server>
</servers>
注:最基本的設置,在同一機器上。
3.2高級設置:
<clients>
<client host=」louxor」 weight=」1″ maxusers=」800″>
<ip value=」10.9.195.12″></ip>
<ip value=」10.9.195.13″></ip>
</client>
<client host=」memphis」 weight=」3″ maxusers=」600″ cpu=」2″/>
</clients>
<servers>
<server host=」10.9.195.1″ port=」8080″ type=」tcp」></server>
</servers>
能夠用多個虛擬IP來模擬出更多的機器,在負載均衡器使用客戶端IP把流量分配到服務端集羣中時,這點十分有用。
在這個例子中,第二個機器在tsung集羣中,它被設定更高的比重、兩個cpu。它用兩個erlang虛擬機來充分利用cpu數量。
注意:即便如今erlang vm能處理多個cpu(erlang SMP),測試顯示,對一個tsung客戶端來講,一個cpu用一個vm更高效。所以你的cpu數最好和你的結點數相等。若是你還堅持用erlang SMP,在啓動tsung加上-s選項,而且不要在配置文件中設定cpu個數。
默認狀況下,負載被統一的分配到全部的cpu上(默認一個客戶端一個cpu)。參數的比重能夠用來衡量客戶端機器的處理速度。例如,有兩臺真實機器,一臺比重爲1,另外一臺爲2,那麼第二臺機器會比第一臺機器多啓動一倍的用戶(比重是1/3,2/3).在上面的例子中,第二臺機器有2個cpu比重是3,這就至關於每一個cpu的比重是1.5。
參數maxusers被用來忽略單個進程對套接字打開數的限制(默認是1024)。當用戶數高於這個限制後,就會啓動一個新的vm來處理新的用戶。參數maxusers的默認值是800。如今的機器開啓kernel poll功能後,你就能夠對maxusers設定一個最高的值(如30000)而沒有性能損失(但注意不要忘記用ulimit -n提升os的限制[這點不大明白]),
3.3運行一個帶有做業調度器的tsung[不理解]
原文在文檔6.2.3
4、監控標籤
tsung監控多個遠程服務器, 每一個遠程服務器都是由多個用遠程代理進行交互的後臺。這個能夠在<monitor>標籤中配置。可統計的數據有:cpu使用狀況,平均的工做量狀況,內存利用狀況。
這兒注意:你能夠從做業調試器獲得監控結點,如:
<monitor batch=」true」 host=」torque」 type=」erlang」></monitor>
這兒支持多種類型的遠程代理(默認是erlang)。
4.1
5、負載標籤
5.1隨機生成用戶
負載標籤訂義了幾個用戶到達階段
<load>
<arrivalphase phase=」1″ duration=」10″ unit=」minute」>
<users interarrival=」2″ unit=」second」></users>
</arrivalphase>
<arrivalphase phase=」2″ duration=」10″ unit=」minute」>
<users interarrival=」1″ unit=」second」></users>
</arrivalphase>
<arrivalphase phase=」3″ duration=」10″ unit=」minute」>
<users interarrival=」0.1″ unit=」second」></users>
</arrivalphase>
</load>
上面這段配置文件表示:用戶的生成分三個階段,第一階段,每2秒生成一個新用戶;第二階段,每秒生成一個新用戶,第三階段,每秒生成10個新用戶。這些測試將在全部用戶執行完它們的過程(後面的session標籤表明的過程)以後,整個測試就結束了。
上面的第三階段是每秒生成10個用戶,但它字面上理解是每0.1秒生成一個用戶,你還能夠經過另外一種方法實現一樣的功能,用arrivalrate來代替arrivalphase,例:
<arrivalphase phase=」1″ duration=」10″ unit=」minute」>
<users arrivalrate=」10″ unit=」second」></users>
</arrivalphase>
還能夠用load標籤中用loop屬性來讓整個過程執行屢次,如:loop=’2′的意思是這序列被循環兩次,因此成天負載被執行三次。(這個要在版本1.2.2以後可用)
負載由每秒http的請求數和每一個session的request的個數來決定,例如:每一個session有100個request, 每秒生成10個新用戶,那麼理論的平均吞吐量是每秒1000個request。
5.2靜態生成用戶
你想在測試的過程當中在指定的時間上啓動給定的session,你的願望在1.3.1版本以後能夠實現。
<load>
<arrivalphase phase=」1″ duration=」10″ unit=」minute」>
<users interarrival=」2″ unit=」second」></users>
</arrivalphase>
<user session=」http-example」 start_time=」185″ unit=」second」></user>
<user session=」http-example」 start_time=」10″ unit=」minute」></user>
<user session=」foo」 start_time=」11″ unit=」minute」></user>
</load>
<sessions>
<session name=」http-example」 probability=」0″ type=」ts_http」>
<request> <http url=」/」 method=」GET」></http> </request>
</session>
<session name=」foo」 probability=」100″ type=」ts_http」>
<request> <http url=」/」 method=」GET」></http> </request>
</session>
<sessions>
在這個例子中,有兩個session,一個的probability爲「0」(所以在第一階段不會被執行,就是隨機生成用戶部分), 而另外一個是100。在測試開始以後,咱們設置3個用戶分別啓動,第一個在3分5秒(執行http-example session)啓動,第二個在10分鐘後啓動(http-example session),最後一個在11分鐘後啓動(foo session)。
5.3負載測試的過程
默認狀況下,tsung在全部用戶都完成他們的session以後結束,所以這會比用戶生成的過程要長的多。若是你想要中止tsung而無論階段是否完成,也不論是否有session正處於激活狀態。那麼你能夠在load標籤中增長duration屬性(版本1.3.2後有效)。
<load duration=」1″ unit=」hour」>
<arrivalphase phase=」1″ duration=」10″ unit=」minute」>
<users interarrival=」2″ unit=」second」></users>
</arrivalphase>
</load>
當前最大值是50天,unit能夠是」second」, 「minute」, 「hour」。
6、option標籤:
全局變量的默認值能夠在這兒進行設定,好比:場景中兩次請求間的思考時間,ssl加密算法,tcp/udp緩存大小(默認是32K)。若是override設置爲true,這些值會把session配置文件中的對應值覆蓋。
<option name=」thinktime」 value=」3″ random=」false」 override=」true」/>
<option name=」ssl_ciphers」 value=」EXP1024-RC4-SHA,EDH-RSA-DES-CBC3-SHA」/>
<option name=」tcp_snd_buffer」 value=」16384″></option>
<option name=」tcp_rcv_buffer」 value=」16384″></option>
<option name=」udp_snd_buffer」 value=」16384″></option>
<option name=」udp_rcv_buffer」 value=」16384″></option>
注:在1.3.1版本以後,增長一個屬性——hibernate,這個被用來減小模擬用戶在思考時間的內存消耗。默認狀況下,當思考時間超過10s以後hibernate就會被激活,這個能夠進行修改,如:
<option name=」hibernate」 value=」5″></option>
想要禁止hibernate時,把值設爲」infinity」
6.1XMPP/Jabber 選項
暫略…
6.2http 選項
對應http,你能夠設定UserAgent的值[版本1.1.0後],對每一個user_agent都有一個probability屬性(全部的probability值的和是100),如:
<option type=」ts_http」 name=」user_agent」>
<user_agent probability=」80″>
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21
</user_agent>
<user_agent probability=」20″>
Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
</user_agent>
</option>html

7、session標籤
session定義了場景自己,它描述了要運行的請求。
每一個session都有一個指定的probality屬性,這個被用來決定一個新用戶要運行哪一個session,全部session的probability屬性和爲100。
一個事務是一種手工統計數據的一種方式。好比說你想知道你網站登陸頁面的反應時間,你就須要把這個頁面的全部請求(html和內嵌的圖片等)放到這個事務裏面。在下面的例子中你就會看到,名爲index_request的事務統計數據和報告。這兒要注意的是,若是思考時間也是請求的一部分的話,你也要在事務中加入思考時間。
7.一、思考時間
你能夠對每個單獨的請求分配一個固定的或隨機的思考時間,默認狀況下,隨機思考時間是以value爲基準的指數分佈
<thinktime value=」20″ random=」true」></thinktime>
這兒思考時間就是以20爲基準的指數分佈。
1.3.0版本以後,還增長了一個範圍的控制,能夠設定一個最大最小值,隨機時間就在最大最小值之間波動
<thinktime min=」2″ max=」10″ random=」true」></thinktime>
7.二、http協議
下面這個例子展現了http協議的多種上特性:get, post請求、基本的認證、事務、數據統計定義、狀態請求(if modified since)
<sessions>
<session name=」http-example」 probability=」70″ type=」ts_http」>
<request>
<http url=」/」 method=」GET」 version=」1.1″></http>
</request>
<request>
<http url=」/images/logo.gif」 method=」GET」 version=」1.1″ if_modified_since=」Fri, 14 Nov 2003 02:43:31 GMT」> </http>
</request>
<thinktime value=」20″ random=」true」></thinktime>
<transaction name=」index_request」>
<request>
<http url=」/index.en.html」 method=」GET」 version=」1.1″ ></http>
</request>
<request>
<http url=」/images/header.gif」 method=」GET」 version=」1.1″> </http>
</request>
</transaction>
<thinktime value=」60″ random=」true」></thinktime>
<request>
<http url=」/」 method=」POST」 version=」1.1″ contents=」bla=blu」> </http>
</request>
<request>
<http url=」/bla」 method=」POST」 version=」1.1″ contents=」bla=blu&amp;name=glop」>
<www_authenticate userid=」Aladdin」 passwd=」open sesame」/>
</http>
</request>
</session>
<session name=」backoffice」 probability=」30″ …>
… </session>
</sessions>
在1.2.2版本以後,你還能夠像下面這樣增長任何的http頭:
<request>
<http url=」/bla」 method=」POST」 contents=」bla=blu&amp;name=glop」>
<www_authenticate userid=」Aladdin」 passwd=」open sesame」/>
<http_header name=」Cache-Control」 value=」no-cache」/>
<http_header name=」Referer」 value=」http://www.w3.org/」/>
</http>
</request>
在版本1.3.0你能夠從外部文件中讀取post和put的內容。
<http url=’mypage’ method=’POST’ contents_from_file=’/tmp/myfile’ />
在版本1.3.1以後,你還能夠手工的設定一個cookie,因爲cookie不是可持久的,因此你要在每一個的請求中增長它個代碼
<http url=」/」>
<add_cookie key=」foo」 value=」bar」/>
<add_cookie key=」id」 value=」123″/>
</http>
7.3~7.7暫略算法

8、高級配置
8.一、動態替換
8.二、讀外部文件
8.三、動態變量
8.四、檢查服務器反應
8.五、循環、選擇(loop,if)
在1.3.0版本後,能夠增長條件/非條件循環:
8.5.一、<for>:
from:初使值
to:最終值
incr:增量
var:保存當數值的變量名
<for from=」1″ to=」10″ incr=」1″ var=」counter」>
[...]
<request> <http url=」/page?id=%%_counter%%」></http> </request>
[...]
</for>
8.5.二、<repeat>
name:循環名
max_repeat:循環次數
注意:循環的最後一個標籤是<while>或<until>
<repeat name=」myloop」 max_repeat=」40″>
[...]
<request>
<dyn_variable name=」result」 regexp=」Result: (.*)」/>
<http url=」/random」 method=」GET」 version=」1.1″></http>
</request>
[...]
<until var=」result」 eq=」5″/>
</repeat>
8.5.三、<if>
1.3.1版本後,支持基於動態變量的if表達式
<if var=」tsung_userid」 eq=」3″>
<request> <http url=」/foo」/> </request>
<request> <http url=」/bar」/> </request>
</if>
你能夠用eq或neq來檢查變量緩存

9、數據統計與報告
9.一、可用屬性
request:每次請求的請求時間
page:一系列請求的請求時間(一個頁面是不包含「思考時間「的一系列請求)
connect:鏈接創建的過程
reconnect:從新鏈接的數量
size_rcv:反應的大小(單位是byte)
size_sent:請求的大小(單位是byte)
session:一個用戶會話的持續時間
users:同步用戶的數量
connected:同步鏈接用戶的數量
custom transaction:
9.二、設計
9.3生成報告
首先進行你測試的log日誌目錄(「~/.tsung/log/yyyyMMdd-hhmm/」),而後進行控制檯,執行:」tsung_stats.pl」(完整命令/usr/lib/tsung/bin/tsung_stats.pl)
你甚至能夠在測試運行的時候,生成統計數據。
使用-help能夠察看全部的可變選項:
9.4tsung摘要
Available options:
[--help] (this help text)
[--verbose]
[--debug]
[--noplot] (don’t make graphics)
[--gnuplot <command>] (path to the gnuplot binary)
[--nohtml] (don’t create HTML reports)
[--logy] (logarithmic scale for Y axis)
[--tdir <template_dir>] (Path to the HTML tsung templates)
[--noextra (don’t generate graphics from extra data (os monitor, etc)
[--stats <file>] (stats file to analyse, default=tsung.log)服務器

9.5圖形概述
可查看附件20110531-10:33.tar.gz(這是我本身運行後的文件的壓縮包)
9.6tsung繪圖
9.7RRDcookie

 

轉自:http://blog.programfan.info/tsung/178.jspsession

相關文章
相關標籤/搜索