压力测试工具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
- To start it, run tsung-recorder -p <PLUGIN> start, where PLUGIN can be http, webdav or pgsql for PostgreSQL. The default plugin is http.
- The proxy is listening to port 8090. You can change the port with -L portnumber.
- To stop it, use tsung-recorder stop.
- 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
- 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’>’’
- 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&string=010004%%_useridend%%' version='1.1' method='GET'></http> </request> <request subst="true"> <dyn_variable name="auth" re="<auth relpy="(.*)"/>"/> <dyn_variable name="entoken" re="<token value="(.*)"/>"/> <http url='/app/test/index.php?version=1.1&action=auth&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&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="<upgrade result="([^"]*)">"/> <dyn_variable name="upgradever" re="<swinfo version="([^"]*)""/> <http url='/app/test/index.php?version=1.1&action=update&hw_version=10.0.0&swversion=3&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&result=0&oldversion=3&curversion=%%_upgradever%%&token=%%_token%%&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
一、安装
安装环境:
- LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
- Distributor ID: CentOS
- Description: CentOS release 6.5 (Final)
- Release: 6.5
- Codename: Final
在安装之前确保安装了以下工具:
- yum install gcc -y
- yum install perl -y
- yum install unixODBC
- yum install unixODBC-devel
- # wget http://www.erlang.org/download/otp_src_R14B04.tar.gz
- # tar -zxvf otp_src_R14B04.tar.gz
- # cd otp_src_R14B04
- # ./configure --prefix=/usr/local/erlang
- # make
- # make install
- yum install -y ncurses-devel
- # wget http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz
- # tar -zxvf tsung-1.4.2.tar.gz
- # cd tsung-1.4.2
- # ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/erlang
- # make
- # make install
- # wget http://cpan.org/modules/by-module/Template/Template-Toolkit-2.24.tar.gz
- # tar -zxvf Template-Toolkit-2.24.tar.gz
- # cd Template-Toolkit-2.24
- # perl Makefile.PL
- # make
- # make test
- # make install
- # yum install -y gnuplot gd libpng zlib
注意:安装成后添加erlang、tsung环境变量
- # vim /etc/profile
- export PATH=$PATH:$JAVA_HOME/bin:/usr/local/erlang/bin:/usr/local/tsung/bin:/usr/local/nginx/sbin:$PATH(修改自己实际变量)
- :x保存,退出
- # source /etc/profile
- 不报错则成功
- # tsung -v
- # erl -v
- 测试
二、使用
- <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>
- <span style="font-family: SimSun;"># cp /usr/local/tsung/share/doc/tsung/examples/http_simple.xml ~/.tsung/tsung.xml</span>
- # tsung start
- Starting Tsung
- "Log directory is: /root/.tsung/log/20140817-1801"
更多命令:
- Usage: tsung <options> start|stop|debug|status
- Options:
- -f <file> set configuration file (default is ~/.tsung/tsung.xml)
- (use - for standard input)
- -l <logdir> set log directory (default is ~/.tsung/log/YYYYMMDD-HHMM/)
- -i <id> set controller id (default is empty)
- -r <command> set remote connector (default is ssh)
- -s enable erlang smp on client nodes
- -p <max> set maximum erlang processes per vm (default is 250000)
- -m <file> write monitoring output on this file (default is tsung.log)
- (use - for standard output)
- -F use long names (FQDN) for erlang nodes
- -w warmup delay (default is 10 sec)
- -v print version information and exit
- -6 use IPv6 for Tsung internal communications
- -h display this help and exit
进入Log目录下可以看到生成的报表信息
- # cd /root/.tsung/log/20140817-1801
- # ls -a
- match.log tsung_1b.xml tsung_controller@iZ234cp44ihZ.log tsung.log
- # yum -y install perl5 gnuplot libtemplate-perl
进入需要生成图形报表的Log目录,如/root/.tsung/log/20140817-1801
- # /usr/local/tsung/lib/tsung/bin/tsung_stats.pl
- creating subdirectory data
- creating subdirectory gnuplot_scripts
- creating subdirectory images
- warn, last interval (0) not equal to the first, use the first one (10)
- No data for Event
- No data for Errors
- # ls
- data nuplot_scripts images report.html tsung_controller@iZ234cp44ihZ.log
- gnuplot.log graph.html match.log tsung_1b.xml tsung.log
架设一个Http服务器打开report.html就可以看到生成的报表了.
- 压力测试工具Tsung安装和使用
- 压力测试工具Tsung安装和使用
- CentOS压力测试工具Tsung安装和使用和图形报表生成
- CentOS压力测试工具Tsung安装、使用和图形报表生成
- CentOS压力测试工具Tsung安装、使用和图形报表生成
- CentOS压力测试工具Tsung安装、使用和图形报表生成
- 压力测试工具Tsung
- erlang 压力测试工具 tsung
- 在MacX上安装Xmpp压力测试工具Tsung
- tsung--开源多协议分布式压力测试工具
- tsung--开源多协议分布式压力测试工具 .
- Linux Tsung压力测试安装说明
- Linux Tsung压力测试安装说明
- tsung压力测试
- Tsung压力测试openfire
- Tsung压力测试介绍
- tsung 安装及测试使用
- tsung 安装和测试注册
- C++当中的引用
- Android软件开发之获取通讯录联系人信息
- 获取带事件值的二维码
- 关于Android 自定义属性 declare-styleable 的学习
- js运动-多物体运动
- 压力测试工具Tsung安装和使用
- Android中解析复杂的JSON数据
- 网络安全术语解释
- Android volley 解析(四)之缓存篇
- JSON 数据格式
- 内存管理注意点!!!
- 看不到会比较好办科级干部
- MFC中获取窗口句柄及相关函数
- 解决头文件相互包含问题的方法