Tsung

1 篇文章 0 订阅
1.介绍

    它能用来压力测试HTTP、WebDAV、SOAP、PostgreSQL、Mysql、LDAP和Jabber/XMPP的服务器,可以分步在多个客户机,并能够模拟成千上万的虚拟用户数并发。

    传统压力测试工具要收费,而且很贵,难以扩展,无法很好的集群形成大的压力。Tsung内置HTTP、WebDAV、SOAP、PostgreSQL、Mysql、LDAP和Jabber/XMPP协议,Tsung可以同时模拟上百万用户,如果你有足够多的机器,Tsung稳定可靠。

2.安装

检查是否安装gcc和perl

$ rpm -q gcc

$ rpm -q perl

如果未安装,则安装之:

$ yum install -y gcc

$ yum install -y perl

安装ncurses-devel包(此包不安装,erlang编译时会报错)

$ yum install -y ncurses-devel

安装erlang

由于Tsung是用erlang写的,因此需要安装erlang

$ wget http://www.erlang.org/download/otp_src_17.0.tar.gz
 
$ tar zxvf otp_src_17.0.tar.gz

$ cd otp_src_17.0
 
$ ./configure
 
$ make
 
$ make install

安装Tsung

$ wget http://tsung.erlang-projects.org/dist/tsung-1.5.1.tar.gz
 
$ tar zxvf tsung-1.5.1.tar.gz
 
$ cd tsung-1.5.1
 
$ ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/lib/erlang
 
$ make
 
$ make install

安装perl的Template

$ yum install -y perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
 
$ wget http://cpan.org/modules/by-module/Template/Template-Toolkit-2.25.tar.gz
 
$ tar zxvf Template-Toolkit-2.25.tar.gz
 
$ cd Template-Toolkit-2.25
 
$ perl Makefile.PL
 
$ make
 
$ make install

安装gnuplot(图片生成工具)

$ yum install -y gnuplot gd libpng zlib
 
$ gnuplot
 
$ gnuplot> set terminal
 
#确认是否已经支持png
 
png  PNG images using libgd and TrueType fonts
3.执行
$ tsung -f ***.xml start/stop/debug/status
4.生成报告

进入log目录,执行下面命令后,直接访问report.htm即可。

$ /usr/local/tsung/lib/tsung/bin/tsung_stats.pl
5. 示例

http example

 <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tsung SYSTEM "/usr/local/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0"> 
  <!-- Client side setup -->  
  <clients> 
    <client host="localhost" use_controller_vm="true" maxusers="9999"/> 
  </clients>  
  <!-- Server side setup -->  
  <servers> 
    <server host="www.demo.com" port="80" type="tcp"/> 
  </servers>  
  <!-- to start os monitoring (cpu, network, memory). Use an erlang  
         agent on the remote machine or SNMP. erlang is the default -->  
  <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="120" unit="minute"> 
      <users arrivalrate="15" unit="second"/> 
    </arrivalphase>  
    <arrivalphase phase="2" duration="120" unit="minute"> 
      <users arrivalrate="20" unit="second"/> 
    </arrivalphase>  
    <arrivalphase phase="3" duration="120" unit="minute"> 
      <users arrivalrate="25" unit="second"/> 
    </arrivalphase>  
    <arrivalphase phase="4" duration="120" unit="minute"> 
      <users arrivalrate="30" unit="second"/> 
    </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>  
    <option name="file_server" id="productname" value="/root/.tsung/productname.csv"/>  
    <option name="file_server" id="productid" value="/root/.tsung/productid.csv"/> 
  </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="index" probability="20" type="ts_http"> 
      <request> 
        <http url="/index.php" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session>  
    <session name="search" probability="50" type="ts_http"> 
      <setdynvars sourcetype="file" fileid="productname" delimiter=";" order="iter"> 
        <var name="goods_name"/> 
      </setdynvars>  
      <request subst="true"> 
        <http url="/index.php/gallery.html?scontent=%%_goods_name%%" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session>  
    <session name="product" probability="21" type="ts_http"> 
      <setdynvars sourcetype="file" fileid="productid" delimiter=";" order="iter"> 
        <var name="random_id"/> 
      </setdynvars>  
      <request subst="true"> 
        <http url="/?product-%%_random_id%%.html" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session>  
    <session name="radom" probability="3" type="ts_http"> 
      <request> 
        <http url="/article-help-l-1.html" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session>  
    <session name="radom1" probability="3" type="ts_http"> 
      <request> 
        <http url="/article-news-55.html" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session>  
    <session name="radom2" probability="3" type="ts_http"> 
      <request> 
        <http url="/article-news-l-11.html" version="1.1" method="GET"> 
          <http_header name="Accept-Encoding" value="gzip,deflate"/> 
        </http> 
      </request> 
    </session> 
  </sessions> 
</tsung>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值