压力测试工具Tsung安装和使用

来源:互联网 发布:linux 合并多个文件夹 编辑:程序博客网 时间:2024/05/17 02:29

General

Tsung is an open-source multi-protocol distributed load testing tool, It can be used to stress HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP and Jabber/XMPP servers. Tsung is a free software released under the GPLv2 license.

The purpose of Tsung is to simulate users in order to test the scalability and performance of IP based client/server applications. You can use it to do load and stress testing of your servers. Many protocols have been implemented and tested, and it can be easily extended.

It can be distributed on several client machines and is able to simulate hundreds of thousands of virtual users concurrently (or even millions if you have enough hardware ...).

Tsung is developed in Erlang, an open-source language made by Ericsson for building robust fault-tolerant distributed applications.

Tsung Home: http://tsung.erlang-projects.org/


Installation

Install tsung in CentOS, before installation, please make sure below tools are installed:

  • yum install gcc -y
  • yum install perl -y
  • yum install unixODBC
  • yum install unixODBC-devel

1. Install erlang


















































































































download erlang from http://www.erlang.org/download.html, and select R14B04 version
<span style="color: rgb(102, 102, 102);"><em># wget http://www.erlang.org/download/otp_src_R14B04.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># tar -zxvf otp_src_R14B04.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># cd otp_src_R14B04</em></span><span style="color: rgb(102, 102, 102);"><em># ./configure --prefix=/usr/local/erlang</em></span><span style="color: rgb(102, 102, 102);"><em># make</em></span><span style="color: rgb(102, 102, 102);"><em># make install</em></span>

If raise "configure: error: No curses library functions found" in configure step, please install ncurses-devel and re-try configure:

<span style="color: rgb(102, 102, 102);"># </span><span style="color: rgb(194, 12, 185);"><strong>yum install</strong></span> <span style="color: rgb(102, 0, 51);">-y</span> ncurses-devel


2. Install Tsung

download tsung from http://tsung.erlang-projects.org/dist/.

<span style="color: rgb(102, 102, 102);"><em># wget http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># tar -zxvf tsung-1.4.2.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># cd tsung-1.4.2</em></span><span style="color: rgb(102, 102, 102);"><em># ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/erlang</em></span><span style="color: rgb(102, 102, 102);"><em># make</em></span><span style="color: rgb(102, 102, 102);"><em># make install</em></span>


3. Install perl Template

Template used for Tsung reports generated. Template-Toolkit downlaod link:http://www.template-toolkit.org/download/index.html

<span style="color: rgb(102, 102, 102);"><em># wget http://cpan.org/modules/by-module/Template/Template-Toolkit-2.24.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># tar -zxvf Template-Toolkit-2.24.tar.gz</em></span><span style="color: rgb(102, 102, 102);"><em># cd Template-Toolkit-2.24</em></span><span style="color: rgb(102, 102, 102);"><em># perl Makefile.PL</em></span><span style="color: rgb(102, 102, 102);"><em># make</em></span><span style="color: rgb(102, 102, 102);"><em># make test</em></span><span style="color: rgb(102, 102, 102);"><em># make install</em></span>


4. Install gnuplot

gnuplot is the chat generator.

<span style="color: rgb(102, 102, 102);"># </span><span style="color: rgb(194, 12, 185);"><strong>yum install</strong></span> <span style="color: rgb(102, 0, 51);">-y</span> gnuplot gd libpng zlib

Note: use "gnuplot" command to check the tools installed like:

<span style="color: rgb(102, 102, 102);"># </span>gnuplot<span style="font-weight: bold;">></span> <span style="font-weight: bold;">set</span> terminal


Tsung usage

1 Create Tsung workdir:

<span style="color: rgb(102, 102, 102);">$ </span><span style="color: rgb(194, 12, 185);"><strong>mkdir</strong></span> ~<span style="font-weight: bold;">/</span>.tsung

2. Configure file, use HTTP test as a sample:

<span style="color: rgb(102, 102, 102);">$ </span><span style="color: rgb(194, 12, 185);"><strong>cp</strong></span> <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>local<span style="font-weight: bold;">/</span>tsung<span style="font-weight: bold;">/</span>share<span style="font-weight: bold;">/</span>doc<span style="font-weight: bold;">/</span>tsung<span style="font-weight: bold;">/</span>examples<span style="font-weight: bold;">/</span>http_simple.xml ~<span style="font-weight: bold;">/</span>.tsung<span style="font-weight: bold;">/</span>tsung.xml

Modify the tsung.xml, more usage you can get from: http://tsung.erlang-projects.org/user_manual.html#htoc1

3. Run Tsung for your test

<span style="color: rgb(102, 102, 102);">$ </span>tsung start

4. Test report After the tsung test finished, go to the folder which naming as create time and run the perl script:

$ <span style="color: rgb(122, 8, 116);"><strong>cd</strong></span> ~<span style="font-weight: bold;">/</span>.tsung<span style="font-weight: bold;">/</span>log<span style="font-weight: bold;">/</span>xxxxx$ <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>local<span style="font-weight: bold;">/</span>tsung<span style="font-weight: bold;">/</span>lib<span style="font-weight: bold;">/</span>tsung<span style="font-weight: bold;">/</span>bin<span style="font-weight: bold;">/</span>tsung_stats.pl

5. Display the test results from Firefox or IE If the server installed python, you can start a http server like:

$ <span style="color: rgb(122, 8, 116);"><strong>cd</strong></span> ~<span style="font-weight: bold;">/</span>.tsung<span style="font-weight: bold;">/</span>log<span style="font-weight: bold;">/</span>xxxxx$ python <span style="color: rgb(102, 0, 51);">-m</span> SimpleHTTPServer

Then you can get reports from: http://serverip:8000


Practice


tsung-recorder

Tsung use tsung-recorder to record your test actions and auto generate the

  1. To start it, run tsung-recorder -p <PLUGIN> start, where PLUGIN can be http, webdav or pgsql for PostgreSQL. The default plugin is http.
  2. The proxy is listening to port 8090. You can change the port with -L portnumber.
  3. To stop it, use tsung-recorder stop.
  4. The recorded session is created as ~/.tsung/tsung_recorderYYYMMDD-HH:MM.xml; if it doesn’t work, take a look at ~/.tsung/log/tsung.log-tsung_recorder@hostname
  5. During the recording, you can add custom tag in the XML file, this can be useful to set transactions or comments: tsung-recorder record_tag "<transaction name=’login’>’’
  6. Once a session has been created, you can insert it in your main configuration file, either by editing by hand the file, or by using an ENTITY declaration, like:
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" [ <!ENTITY mysession1 SYSTEM "/home/nniclausse/.tsung/tsung_recorder20051217-13:11.xml"> ]> ...<sessions>  &mysession1;</sessions>


Notes:

  • 将本机测试环境代理服务器IP设置为Tsung机的IP(10.192.110.6),并将端口改为8090
  • 在tsung机上运行 tsung-recorder start 开始录制
  • 在本机测试环境中网页里操作需要录制的步骤
  • 在tsung机上运行 tsung-recorder stop 结束录制


One Tsung cases sample

1. Server and Client configure in tsung.xml file like:

<!-- Client side setup -->    <clients>        <client host="server1" use_controller_vm="true" maxusers="10000" />    </clients>     <!-- Server side setup -->    <servers>        <server host="172.11.10.1" port="80" type="tcp"></server>    </servers>

2. Phases setting in tsung.xml file like:

<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="1" unit="minute">            <users maxnumber="1" interarrival="1" unit="second"></users>        </arrivalphase>    </load>

3. Add session cases file in tsung.xml file like:

<!DOCTYPE tsung SYSTEM "/usr/local/tsung/share/tsung/tsung-1.0.dtd" [ <!ENTITY mysession1 SYSTEM "/root/.tsung/cases_list/tsung_recorder20120828-1339.xml">]>...<sessions>  &mysession1;</sessions>

Make sure /usr/local/tsung/share/tsung/tsung-1.0.dtd existed.

Sample of /root/.tsung/cases_list/tsung_recorder20120828-1339.xml:

<session name='rec20120828-1339' probability='100'  type='ts_http'>         <!--Mock encoded boxid-->        <setdynvars sourcetype="random_string" length="20">                <var name="useridend" />        </setdynvars>         <!-- Use 3des_test.php to mock the 3DES'ed boxid for the auth request -->        <request subst="true">                <dyn_variable name="boxid" re="urlencode:(.*)"/>                <http url='/app/test/test.php?type=encode&amp;string=010004%%_useridend%%' version='1.1' method='GET'></http>        </request>         <request subst="true">                <dyn_variable name="auth" re="&lt;auth relpy=&quot;(.*)&quot;/&gt;"/>                <dyn_variable name="entoken" re="&lt;token value=&quot;(.*)&quot;/&gt;"/>                <http url='/app/test/index.php?version=1.1&amp;action=auth&amp;userid=%%_userid%%' version='1.1' method='GET'></http>        </request>         <if var="auth" eq="success">                 <!-- decode the token -->                <request subst="true">                        <dyn_variable name="token" re="Decode:(.*)"/>                        <http url='/app/test/test.php?type=decode&amp;string=%%_entoken%%' version='1.1' method='GET'></http>                </request>                 <!-- sleep time to mock PAD client operation, if thinktime more than 2 sec, upgrade request will be failed -->                <thinktime random='true' value='1'/>                 <!-- upgrade request -->                <request subst="true">                        <dyn_variable name="upgraderesult" re="&lt;upgrade result=&quot;([^&quot;]*)&quot;&gt;"/>                        <dyn_variable name="upgradever" re="&lt;swinfo version=&quot;([^&quot;]*)&quot;"/>                        <http url='/app/test/index.php?version=1.1&amp;action=update&amp;hw_version=10.0.0&amp;swversion=3&amp;token=%%_token%%' version='1.1' method='GET'></http>                </request>                 <if var="upgraderesult" eq="0">                        <!-- download request -->                        <request subst="true">                                <http url='/app/test/download.php?token=%%_token%%' version='1.1' method='GET'></http>                        </request>                         <!-- confirm request -->                        <request subst="true">                                <http url='/app/test/index.php?action=confirm&amp;result=0&amp;oldversion=3&amp;curversion=%%_upgradever%%&amp;token=%%_token%%&amp;version=1.1' version='1.1' method='GET'></http>                        </request>                </if>        </if>  </session>

Descriptions:

  • random_string:
<setdynvars sourcetype="random_string" length="20">   <var name="useridend" /> </setdynvars>

Means a dynamic variable can be a random string "useridend", its lenght 20. BTW, a dynamic variable can be a random number by random_number

  • <dyn_variable name="userid" re="urlencode:(.*)"/>: means get boxid values using regular expression to filter from http response.
  • Using a variable like %%_userid%%
  • When you want to use dynamic variables, please using the subst attribut in request element



中文:

一、安装

安装环境:

[plain] view plaincopy
  1. LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch  
  2. Distributor ID: CentOS  
  3. Description:    CentOS release 6.5 (Final)  
  4. Release:        6.5  
  5. Codename:       Final  

在安装之前确保安装了以下工具:

[plain] view plaincopy
  1. yum install gcc -y  
  2. yum install perl -y  
  3. yum install unixODBC  
  4. yum install unixODBC-devel  

下载并安装erlang
[plain] view plaincopy
  1. # wget http://www.erlang.org/download/otp_src_R14B04.tar.gz  
  2. # tar -zxvf otp_src_R14B04.tar.gz  
  3. # cd otp_src_R14B04  
  4. # ./configure --prefix=/usr/local/erlang  
  5. # make  
  6. # make install  
注意:如果出现 "configure: error: No curses library functions found "错误,尝试安装:
[plain] view plaincopy
  1. yum install -y ncurses-devel  
下载并安装Tsung
[plain] view plaincopy
  1. # wget http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz  
  2. # tar -zxvf tsung-1.4.2.tar.gz  
  3. # cd tsung-1.4.2  
  4. # ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/erlang  
  5. # make  
  6. # make install  
下载并安装perl Template,用于生成报告模版
[plain] view plaincopy
  1. # wget http://cpan.org/modules/by-module/Template/Template-Toolkit-2.24.tar.gz  
  2. # tar -zxvf Template-Toolkit-2.24.tar.gz  
  3. # cd Template-Toolkit-2.24  
  4. # perl Makefile.PL  
  5. # make  
  6. # make test  
  7. # make install  
下载并安装gnuplot,用于聊天生成
[plain] view plaincopy
  1. # yum install -y gnuplot gd libpng zlib  

注意:安装成后添加erlang、tsung环境变量

[plain] view plaincopy
  1. # vim /etc/profile   
  2. export PATH=$PATH:$JAVA_HOME/bin:/usr/local/erlang/bin:/usr/local/tsung/bin:/usr/local/nginx/sbin:$PATH(修改自己实际变量)  
  3. :x保存,退出  
  4. # source /etc/profile   
  5. 不报错则成功  
  6. # tsung -v   
  7. # erl -v  
  8. 测试  

二、使用

在root文件夹下新建.tsung目录,用于存放log和xml配置,测试配置文件可参考/usr/local/tsung/share/doc/tsung/examples/目录下配置
[plain] view plaincopy
  1. <pre name="code" class="plain" style="color: rgb(51, 51, 51); font-size: 13px; line-height: 19.046875px;">#<span style="font-family: SimSun;"> mkdir ~/.tsung</span>  
[plain] view plaincopy
  1. <span style="font-family: SimSun;"># cp /usr/local/tsung/share/doc/tsung/examples/http_simple.xml ~/.tsung/tsung.xml</span>  
运行,默认执行脚本~/.tsung/tsung.xml配置
[plain] view plaincopy
  1. # tsung start  
  2. Starting Tsung  
  3. "Log directory is: /root/.tsung/log/20140817-1801"  

更多命令:

[plain] view plaincopy
  1. Usage: tsung <options> start|stop|debug|status  
  2. Options:  
  3.     -f <file>     set configuration file (default is ~/.tsung/tsung.xml)  
  4.                    (use - for standard input)  
  5.     -l <logdir>   set log directory (default is ~/.tsung/log/YYYYMMDD-HHMM/)  
  6.     -i <id>       set controller id (default is empty)  
  7.     -r <command>  set remote connector (default is ssh)  
  8.     -s            enable erlang smp on client nodes  
  9.     -p <max>      set maximum erlang processes per vm (default is 250000)  
  10.     -m <file>     write monitoring output on this file (default is tsung.log)  
  11.                    (use - for standard output)  
  12.     -F            use long names (FQDN) for erlang nodes  
  13.     -w            warmup delay (default is 10 sec)  
  14.     -v            print version information and exit  
  15.     -6            use IPv6 for Tsung internal communications  
  16.     -h            display this help and exit  

进入Log目录下可以看到生成的报表信息

[plain] view plaincopy
  1. # cd  /root/.tsung/log/20140817-1801  
[plain] view plaincopy
  1. # ls -a  
  2. match.log  tsung_1b.xml  tsung_controller@iZ234cp44ihZ.log  tsung.log  
生成图形报表,需要依赖项 gnuplot、perl5及template模板

[plain] view plaincopy
  1. # yum -y install perl5 gnuplot libtemplate-perl    

进入需要生成图形报表的Log目录,如/root/.tsung/log/20140817-1801

[plain] view plaincopy
  1. # /usr/local/tsung/lib/tsung/bin/tsung_stats.pl  
  2. creating subdirectory data   
  3. creating subdirectory gnuplot_scripts   
  4. creating subdirectory images   
  5. warn, last interval (0) not equal to the first, use the first one (10)  
  6. No data for Event  
  7. No data for Errors  
[plain] view plaincopy
  1. # ls   
  2. data    nuplot_scripts  images     report.html   tsung_controller@iZ234cp44ihZ.log  
  3. gnuplot.log  graph.html       match.log  tsung_1b.xml  tsung.log  

架设一个Http服务器打开report.html就可以看到生成的报表了.


0 0
原创粉丝点击