Tsung解析Tsung.xml配置文件
Tsung.xml(HTTP)配置文件模板路径:/usr/share/doc/tsung/examples/http_simple_xml <?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<!-- Client side setup -->
<clients>
<client host="localhost" use_controller_vm="true"/>
</clients>
<!-- Server side setup -->
<servers>
<server host="myserver" port="80" type="tcp"></server>
</servers>
<!-- to start os monitoring (cpu,network,memory). Use an erlang agent on the remote machine or SNMP. erlang is the default -->
<monitoring>
<monitor host="myserver" type="snmp"></monitor>
</monitoring>
<load>
<!-- several arrival phases can be set: for each phase,you can set the mean inter-arrival time between new clients and the phase duration -->
<arrivalphase phase="1" duration="10" unit="minute">
<users interarrival="2" unit="second"></users>
</arrivalphase>
</load>
<options>
<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>
</options>
<!-- start a session for a http user. the probability is the frequency of this type os session. The sum of all session's probabilities must be 100 -->
<sessions>
<session name="http-example" probability="100" type="ts_http">
<!-- full url with server name,this overrides the "server" config value -->
<request> <http url="/" method="GET" version="1.1"></http> </request>
<request> <http url="/images/accueil1.gif" method="GET" version="1.1" if_modified_since="Fri,14 Nov 2003 02:43:31 GMT"></http> </request>
<request> <http url="/images/accueil2.gif" method="GET" version="1.1" if_modified_since="Fri,14 Nov 2003 02:43:31 GMT"></http> </request>
<request> <http url="/images/accueil3.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>
<request> <http url="/index.en.html" method="GET" version="1.1" ></http> </request>
</session>
</sessions>
</tsung>
文件结构客户端和服务器配置基本配置非分布式负载 <!-- 客户端 -->
<clients>
<client host="localhost" use_controller_vm="true"/>
</clients>
<!-- 服务器 -->
<servers>
<server host="192.168.1.1" port="80" type="tcp"></server>
</servers>
添加服务器设置 <servers>
<server host="server1" port="80" type="tcp" weight="4"></server>
<server host="server2" port="80" type="tcp" weight="1"></server>
</servers>
高级配置分布式测试,负载均衡测试,分配不同的流量 <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>
maxusers:该参数用来设置单个线程中创建socket连接的数目 MonitoringTsung通过和远程代理进行通信来对服务器进行监控。 <monitor batch="true" host="torque" type="erlang"></monitor>
Erlang远程代理由Tsung启动,通过Erlang通信检索服务器上活动的统计数据。 <monitoring>
<monitor host="geronimo" type="erlang"></monitor>
<monitor host="bigfoot-1" type="erlang"></monitor>
<monitor host="bigfoot-2" type="erlang"></monitor>
<monitor host="f14-1" type="erlang"></monitor>
<monitor host="f14-2" type="erlang"></monitor>
<monitor host="db" type="erlang"></monitor>
</monitoring>
Erlang对MySQL数据库的监控: <monitor host="db" type="erlang"></monitor>
<mysqladmin port="3306" username="root" password="sesame" />
</monitor>
SNMP默认版本为:v1,端口为:161 <monitoring>
<monitor host="geronimo" type="snmp"/>
<monitor host="f14-2" type="erlang"></monitor>
<monitor host="db" type="snmp">
<snmp version="v2" community="mycommunity" port="11161"/>
</monitor>
</monitoring>
1.4.2版本开始自定义OID <monitor host="127.0.0.1" type="snmp">
<snmp version="v2">
<oid value="1.3.6.1.4.1.42.2.145.3.163.1.1.2.11.0" name="heapused" type="sample" eval="fun(X)-> X/100 end."/>
</snmp>
</monitor>
Munin从1.3.1开始,Tsung可以通过Munin代理检索数据 <monitoring>
<monitor host="geronimo" type="munin"/>
<monitor host="f14-2" type="erlang"></monitor>
</monitoring>
定义负载进程随机产生用户<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>
代码解释 <arrivalphase phase="1" duration="10" unit="minute">
<users arrivalrate="10" unit="second"></users>
</arrivalphase>
或者通过maxnumber属性设置每个阶段最大用户数 <arrivalphase phase="1" duration="10" unit="minute">
<users maxnumber="100" arrivalrate="10" unit="second"></users>
</arrivalphase>
<arrivalphase phase="2" duration="10" unit="minute">
<users maxnumber="200" arrivalrate="10" unit="second"></users>
</arrivalphase>
<arrivalphase phase="3" duration="1" unit="minute">
<session_setup name="http_test_1" probability="80"/>
<session_setup name="fake" probability="20"/>
<users interarrival="1" unit="second"/>
</arrivalphase>
静态生成用户<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="foobar" probability="0" type="ts_http">
<request> <http url="/bar" method="GET"></http> </request>
</session>
<session name="foo" probability="100" type="ts_http">
<request> <http url="/" method="GET"></http> </request>
</session>
<sessions>
上述设置中:包含两个会话信息,probability为0的会话将不会被执行,定义了三个用户,分别在测试开始185秒的http-example会话,一个开始为10分钟后,另一个在11分钟后的foo会话。 <user session="foo*" start_time="10" unit="second"/>
负载测试时间Tsung运行时间取决于测试阶段的总时长,设置测试时间停止Tsung <load duration="1" unit="hour">
<arrivalphase phase="1" duration="10" unit="minute">
<users interarrival="2" unit="second"></users>
</arrivalphase>
</load>
duration : 最大值 < 50days,单位可取:seconds,minute,hour. 设置属性Thinktimes,SSL,Buffers默认设置为全局属性, <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.6.0中,可禁用SSL 会话缓存(默认开启) <option name="ssl_reuse_sessions" value="false"/>
TCP连接超时1.6.0新属性 <option name="connect_timeout" value="5000" />
或者通过set_option标签为每一个会话连接设置超时时间 <set_option name="connect_timeout" value="1000" />
开启TCP地址重复绑定 <option name=”tcp_reuseaddr” value=”true” />
重连次数与超时1.6.0新属性 <option name="max_retries" value="5" />
重连超时:默认为10毫秒 <set_option name="retry_timeout" value="1000" />
超时消息确认设置idle超时,默认10min和全局ack超时,默认无穷 <option name="idle_timeout" value="300000"></option>
<option name="global_ack_timeout" value="6000000"></option>
Hibernate1.3.1 Rate_limit1.4.1 <option name="rate_limit" value="1024"></option>
Ports_range当要在同一客户端下产生30000个连接,必须限制TCP端口号 <option name="ports_range" min="1025" max="65535"/>
设置随机数种子<option name="seed" value="42"/>
设置BOSH路径<option name="bosh_path" value="/http-bind/"/>
Websocket选项使用Websocket服务器模式,设置传输数据格式 <option name="websocket_path" value="/chat"/>
<!-- send websocket data with text frame,default binary-->
<option name="websocket_frame" value="text"/>
XMPP/Jabber选项默认设置 <option type="ts_jabber" name="global_number" value="5" />
<option type="ts_jabber" name="userid_max" value="100" />
<option type="ts_jabber" name="domain" value="jabber.org" />
<option type="ts_jabber" name="username" value="myuser" />
<option type="ts_jabber" name="passwd" value="mypasswd" />
<option type="ts_jabber" name="muc_service" value="conference.localhost"/>
HTTP选项设置用户代理 <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>
AMQP选项<option type="ts_amqp" name="heartbeat" value="30" />
会话会话主要定义脚本内容,描述执行的请求 <session name="s1" weight="2" type="ts_http">
<session name="s2" weight="1" type="ts_http">
http <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&name=glop">
<www_authenticate userid="Aladdin" passwd="open sesame"/></http>
</request>
</session>
<session name="backoffice" probability="30" ...>
...
</session>
</sessions>
HTTP 报头 <request>
<http url="/bla" method="POST" contents="bla=blu&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>
从外部文件读取报文内容 <http url="mypage" method="POST" contents_from_file="/tmp/myfile" />
Cookie,cookie值非持久化的,所以必须在所有的请求中添加 <http url="/">
<add_cookie key="foo" value="bar"/>
<add_cookie key="id" value="123"/>
</http>
认证: <!-- 1. First request return 401. We use dynvars to fetch nonce and realm -->
<request>
<dyn_variable name="nonce" header="www-authenticate/nonce"/>
<dyn_variable name="realm" header="www-authenticate/realm"/>
<http url="/digest" method="GET" version="1.1"/>
</request>
<!-- 2. This request will be authenticated. Type="digest" is important. We use the nonce and realm values returned from the previous If the webserver returns the nextnonce we set it to the nonce dynvar for use with the next request. Else it stays set to the old value -->
<request subst="true">
<dyn_variable name="nonce" header="authentication-info/nextnonce"/>
<http url="/digest" method="GET" version="1.1">
<www_authenticate userid="user" passwd="passwd" type="digest" realm="%%_realm%%" nonce="%%_nonce%%"/>
</http>
</request>
OAuth认证 <!-- Getting a Request Token --> <request> <dyn_variable name="access_token" re="oauth_token=([^&]*)"/> <dyn_variable name="access_token_secret" re="oauth_token_secret=([^&]*)" /> <http url="/oauth/example/request_token.php" method="POST" version="1.1" contents="empty"> <oauth consumer_key="key" consumer_secret="secret" method="HMAC-SHA1"/> </http> </request> <!-- Getting an Access Token --> <request subst=’true’> <dyn_variable name="access_token" re="oauth_token=([^&]*)"/> <dyn_variable name="access_token_secret" re="oauth_token_secret=([^&]*)"/> <http url="/oauth/example/access_token.php" method="POST" version="1.1" contents="empty"> <oauth consumer_key="key" consumer_secret="secret" method="HMAC-SHA1" access_token="%%_access_</http> </request> <!-- Making Authenticated Calls --> <request subst="true"> <http url="/oauth/example/echo_api.php" method="GET" version="1.1"> <oauth consumer_key="key" consumer_secret="secret" access_token="%%_access_token%%" access_token_</http> </request>
高级功能Dynamic substitutionsReading external file动态变量检查服务器响应Loops,If,Foreach1.3.0开始,可在会话中添加有条件或无条件的循环。 <for from="1" to="10" incr="1" var="counter">
...
<request> <http url="/page?id=%%_counter%%"></http></request>
...
</for>
repeat <repeat name="myloop" max_repeat="40">
...
<request>
<dyn_variable name="result" re="Result: (.*)"/>
<http url="/random" method="GET" version="1.1"></http>
</request>
...
<until var
if(版本1.3.1以后) <if var="tsung_userid" eq="3">
<request> <http url="/foo"/> </request>
<request> <http url="/bar"/> </request>
</if>
foreach <foreach name="element" in="list">
<request subst="true">
<http url="%%_element%%" method="GET" version="1.1"/>
</request>
</foreach>
通过include,exclude标签,可以进行元素的包含和排除 <foreach name="element" in="list" include="^/.*$">
<foreach name="element" in="list" exclude="http://.*.tld.com/.*$">
检索图片 <request subst="true">
<dyn_variable name="img_list" xpath="//img/@src"/>
<http url="/mypage.html" method="GET" version="1.1"/>
</request>
<foreach name="img" in="img_list">
<request subst="true">
<http url="%%_img%%" method="GET" version="1.1"/>
</request>
</foreach>
速率限制1.4.0 目前只能限制流入速率 <session name="http-example" probability="70" type="ts_http">
<set_option name="rate_limit" value="64" />
...
</session>
排除请求在启动测试前,通过-x 忽略指定名字的请求 <request>
<http url="/" method="GET"></http>
</request>
<request tag="image">
<http url="/foo.png" method="GET"></http>
</request>
客户端证书1.5.1 <session name="https-with-cert" probability="70" type="ts_http">
<set_option name="certificate">
<certificate cacertfile="/etc/ssl/ca.pem" keyfile="%%_keyfile%%" keypass="%%_keypass%%" certfile="/home/nobody/.tsung/client.pem"/>
</set_option>
</session>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |