ROPERTIES:
:type: KnowledgeBase_Cloud
:END:

  • 开源、多协议、分布式的压力测试工具
 
Item Summary
tsung-recorder start 通过proxy来录音http的测试脚本
tsung start 启动tsung测试
/usr/local/lib/tsung/bin/tsung_stats.pl 针对测试后的log, 生成报表
/usr/lib/tsung/bin/tsung_stats.pl 针对测试后的log, 生成报表
ls /usr/lib/erlang/lib/tsung-1.4.1/src tsung sourcecode location after installation
插件实现 –> get_message builds the actual data to be transmitted to the server.
插件实现 –> parse deals with server responses
插件实现 –> ts_mon 维护各类计数器

Table Of Content

1 basic use

tsung 采用了巧妙的 proxy 方式来“录制”测试脚本。具体来说,就是建立一个本机的 http proxy 默认
使用 8090 端口,在配好 firefox 使用 localhost 8090 作为代理之后,所有“流经”这个 proxy 的
http 动作都会被记录下来,测试时可以“回放”这些步骤来产生请求。

2 tsung的工作原理

  • Tsung的每一个虚拟用户就是一个erlang的轻量进程。这点和loadrunner有很大的区别。
  • 虚拟用户完成session后就消失。
  • 大量的虚拟用户(erlang轻量进程)建立在erlangVM上
  • 一台测试机可以启多个erlangVM,目前按照1个cpu启动1个erlangVM
  • 每个虚拟机下有很多用户,每个用户可以产生很多session,一个session由很多request组成
  • 分布式部署Tsung在运行时,会产生ssl_esock、beam、beam.smp3种进程
    ssl-esock是erlangVM用的port程序, 协助完成ssh功能;beam是单处理器版本的erlangVM;beam.smp就是control程序,负责协调系统的运作。

3 Main features

  • High Performance: the load can be distributed on a cluster of client machines
  • Multi-protocols using a plugin system: HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP and XMPP/Jabber are currently supported. SSL is also supported.
  • Several IP addresses can be used on a single machine using the underlying OS IP Aliasing
  • OS monitoring (CPU, memory and network traffic) using SNMP, Munin or Erlang agents on remote servers.
  • XML configuration system; several sessions can be used to simulate different type of users. Dynamic sessions can be easily described in XML (this can be used to retrieve at runtime an ID from the server output and use it later in the session).
  • In order to generate a realistic traffic, user think-times and the arrival rate can be randomize using a probability distribution
  • HTML reports can be generated during the load to view response times measurement, server CPU, etc.

5 重要网页

 

5.1 web page: tsung安装与使用 » Taobao QA Team

http://qa.taobao.com/?p=8122\\

5.2 web page: Tsung, open source Load Testing

http://loadstorm.com/2008/tsung-open-source-load-testing\\

5.3 web page: Writing a Tsung plugin | Process-one

http://www.process-one.net/en/wiki/Writing_a_Tsung_plugin/\\

6 Tsung programming model

 

6.1 maxusers参数: 决定一个节点能够支持的最多虚拟用户数。

超过该数后, 会自动开启更多的节点。

6.2 IP别名技术, 模拟多个机器

  • 方便服务器作为loadbalance
  • 解决单个IP的端口65535问题

6.3 Weight参数: 决定了每个节点上面用户的比例

 

6.4 DONE Tsung Transaction

CLOSED: 2011-12-20 17:07
http://tsung.erlang-projects.org/user\_manual.html#htoc37

A transaction is just a way to have customized statistics. Say if you want to know the
response time of the login page of your website, you just have to put all the requests of
this page (HTML + embedded pictures) within a transaction. In the example above, the
transaction called index_request will gives you in the statistics/reports the mean
response time to get index.en.html + header.gif. Be warn that If you have a thinktime
inside the transaction, the thinktime will be part of the response time.

7 # –8<————————– §separator§ ————————>8–

 

8 Trouble shooting

 

8.1 DONE tsung client中host应该是可达的hostname, 否则会出现Can’t start newbeam

CLOSED: 2011-12-20 15:35

http://tsung.erlang-projects.org/user\_manual.html#htoc80

  <clients>
          <client host="ecae-test-denny" cpu="2" weight="2" maxusers="100">
<ip scan="true" value="eth0"/>
          </client>
  </clients>

9 tsung report

报告中的几个相似概念:

request:类似用php函数file_get_contents请求一个url地址的相应时间

page:一组没有间隔的request请求的时间总和,相当于打开一个页面,除了加载页面的html外,还要加载img、css、js等

session:一个用户从第一个请求开始到最后一个请求结束的时间总和

10 DONE tsung给出更多信息: dumptraffic=”true”    IMPORTANT

CLOSED: 2011-12-21 21:02

 <?xml version="1.0"?>
 <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
 <tsung loglevel="debug" dumptraffic="true" version="1.0">
   <clients>
     <client host="ecae-test-denny" cpu="2" weight="2" maxusers="1000">
       <ip scan="true" value="eth0"/>
     </client>
  </clients>

...

11 DONE tsung自定义tsung.xml的位置: tsung -f … start

CLOSED: 2011-12-22 17:22

12 # –8<————————– §separator§ ————————>8–

 

13 DONE Tsung设置测试的最大时间

CLOSED: 2011-12-20 15:53
http://tsung.erlang-projects.org/user\_manual.html#htoc37

 <load duration="1" unit="hour">
  <arrivalphase phase="1" duration="10" unit="minute">
    <users interarrival="2" unit="second"></users>
  </arrivalphase>
</load>

14 DONE Tsung对mysql测试中的变量替换问题

CLOSED: 2011-12-22 17:22

authenticate类型中的变量无法进行替换; 而sql类型中的变量可以进行替换

如果将下面tsung.xml的line 55换成line 54, 那么从生成tsung.dump可以看出%%_db_name%%,没有被替
换, 从而导致认证失败。

14.1 tsung.xml

01  <?xml version="1.0"?>
02  <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
03  <tsung loglevel="debug" dumptraffic="true" version="1.0">
04    <clients>
05      <client host="ecae-test-denny" cpu="2" weight="2" maxusers="1000">
06        <ip scan="true" value="eth0"/>
07      </client>
08    </clients>
09
10    <servers>
11      <server host="ecae-test-denny" port="3306" type="tcp"/>
12    </servers>
13
14    <monitoring>
15      <monitor host="ecae-test-denny" type="erlang"/>
16    </monitoring>
17
18    <load duration="15" unit="second">
19      <arrivalphase phase="0" duration="1" unit="minute">
20        <users arrivalrate="200" unit="second"/>
21      </arrivalphase>
22      <arrivalphase phase="1" duration="1" unit="minute">
23        <users arrivalrate="350" unit="second"/>
24      </arrivalphase>
25      <arrivalphase phase="2" duration="1" unit="minute">
26        <users arrivalrate="1000" unit="second"/>
27      </arrivalphase>
28      <arrivalphase phase="3" duration="1" unit="minute">
29        <users arrivalrate="800" unit="second"/>
30      </arrivalphase>
31      <arrivalphase phase="4" duration="1" unit="minute">
32        <users arrivalrate="2000" unit="second"/>
33      </arrivalphase>
34    </load>
35
36    <options>
37      <option name="file_server" id="rdc_test_account" value="/root/.tsung/testcase/rdc/rdc_test_account.csv"/>
38    </options>
39
40    <sessions>
41      <session probability="100" name="mysql-example" type="ts_mysql">
42        <request>
43          <mysql type="connect" />
44        </request>
45       <setdynvars sourcetype="file" fileid="rdc_test_account" delimiter=";" order="random">
46         <var name="db_name" />
47         <var name="user_name" />
48         <var name="user_password" />
49       </setdynvars>
50        <setdynvars sourcetype="random_number" start="3" end="32">
51          <var name="rndint" />
52        </setdynvars>
53        <request subst="true">
54         <!-- <mysql type="authenticate" database="%%_db_name%%" username="admin" password="" /> -->
55          <mysql type="authenticate" database="test" username="admin" password="" />
56        </request>
57        <setdynvars sourcetype="random_string" length="13">
58          <var name="rndstring1" />
59        </setdynvars>
60        <request subst="true">
61          <mysql type="sql">select "%%_rndstring1%%" </mysql>
62        </request>
63        <request>
64          <mysql type="close"></mysql>
65        </request>
66      </session>
67    </sessions>
68  </tsung>

14.2 rdc_test_account.csv

test;u_2102;5i04bg2kc9n1

15 DONE Tsung session中的request进行模块化的处理, 用以提高测试的复用性

CLOSED: 2011-12-20 17:19
Sample:

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" [
<!ENTITY user_load SYSTEM "/root/.tsung/user_load.xml">
<!ENTITY ecstore_session SYSTEM "/root/.tsung/testcase/ecstore/tsung_recorder_ecstore-simple.xml">
]>

<tsung loglevel="notice" version="1.0">
  <clients>
    <client host="ecae-test-denny" cpu="2" weight="2" maxusers="1000">
      <ip scan="true" value="eth0"/>
    </client>
  </clients>

  <servers>
    <server host="ecstore-test.ecae.local" port="8000" type="tcp"/>
  </servers>

  &user_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="ecstore_search" value="/root/.tsung/testcase/ecstore/list_search.csv"/>
  </options>

  &ecstore_session;

</tsung>

16 DONE 如何替换Tsung中某个erlang的代码实现, 从而方便调试    IMPORTANT

CLOSED: 2011-12-21 21:02
在源代码处

make

/bin/cp -rf ./ebin/ts_config_mysql.beam /usr/lib/erlang/lib/tsung_controller-1.4.1/ebin/ts_config_mysql.beam
/bin/cp -rf ./ebin/ts_config.beam /usr/lib/erlang/lib/tsung_controller-1.4.1/ebin/ts_config.beam

17 DONE Tsung中支持变量

CLOSED: 2011-12-21 13:42
http://tsung.erlang-projects.org/user\_manual.html#htoc62
Tsung User’s manual
http://tiandiou.blog.163.com/blog/static/2355668220115392725727/
压力测试工具tsung用法简介 – 老鳖的日志 – 网易博客

添加请求的变量,在压力测试的过程中,可能需要手机号,用户ID、股票代码之类的变量,tsung支持文件随机读取,可以将这些参数按照一定的规则写入文件,在配置文件中定义读取的规则,就能在请求时拿到文件的内容。定义一个文件服务:

 <options>
       <option name="file_server" id="file1" value="/tmp/x.txt"/>
    </options>
读取,在session段中加入

 <setdynvars sourcetype="file" fileid="file1" delimiter=";" order="random">
               <var name="username" />

  </setdynvars>

<request>
<http url="/b.php?username=%%_username%%" method="GET" version="1.1"></http>
</request>

除了从文件读取,也可以随机产生

      <setdynvars sourcetype="random_string" length="13">
        <var name="rndstring1" />
      </setdynvars>

      <setdynvars sourcetype="random_number" start="3" end="32">
        <var name="rndint" />
      </setdynvars>

18 DONE Tsung的mysql测试

CLOSED: 2011-12-20 18:01
http://tsung.erlang-projects.org/user\_manual.html#htoc59

For MySQL, 4 types of requests are available (same as PostgreSQL):

   1. connect (to a given database with a given username
   2. authenticate (with password or not)
   3. sql
   4. close

This example shows most of the features of a MySQL session:

<session probability="100" name="mysql-example" type="ts_mysql">
 <request>
  <mysql type="connect" />
 </request>
 <request>
  <mysql type="authenticate" database="test" username="test" password="test" />
 </request>
 <request>
  <mysql type="sql">SHOW TABLES</mysql>
 </request>
 <request>
  <mysql type="sql">SELECT * FROM mytable</mysql>
 </request>
 <request>
  <mysql type="close" />
 </request>
</session>

19 DONE User agent连接的浏览器类型, 需要本地包含的吗: 只是模拟, 将该fake信息告诉给远端服务器而已

CLOSED: 2011-12-25 21:45

20 CANCELED tsung在做load test的同时验证测试结果: 从插件的实现来看, 部分结果可以验证

CLOSED: 2011-12-25 21:45

21 CANCELED Tsung的thrift接口: 通过thrift php构造成http请求即可    IMPORTANT Misc

CLOSED: 2011-12-26 11:27

22 DONE Tsung的测试不能并发的问题: 给erlang vm不同的node name

CLOSED: 2011-12-26 15:14
use the -i <id> option to set a unique id for each instance

tsung -f examples/file1.xml -i 1234 start

tsung -f examples/file2.xml -i 1235 start

22.1 useful link

http://lists.process-one.net/pipermail/tsung-users/2009-October/001328.html
[Tsung] Tsung 1.3.1. Instances in parallel?
http://lists.process-one.net/pipermail/tsung-users/2009-April/001236.html
[Tsung] Can’t run multiple tsung controllers in parallel

23 DONE tsung get unique id: ts_user_server:get_unique_id, random

CLOSED: 2011-12-28 16:26

,----------- ts_user_server:get_unique_id
|       <setdynvars sourcetype="erlang" callback="ts_user_server:get_unique_id">
|         <var name="ran_num" />
|       </setdynvars>
`-----------

,----------- random_number
|     <setdynvars sourcetype="random_number" start="1" end="100000">
|       <var name="ran_num"/>
|     </setdynvars>
`-----------

24 DONE 服务器监控(CPU, 内存, 网络流量), 支持SNMP, Erlang, MUnin方式

CLOSED: 2011-12-27 18:57

25 DONE http测试时bypass, 用户名和密码的认证: 通过regexp来获取http返回的sessionid, 然后通过tsung的add_cookie强制设置cookie

CLOSED: 2012-02-06 15:31

26 check server response: match

http://tsung.erlang-projects.org/user\_manual.html

6.7.4  Checking the server’s response

With the tag match in a request tag, you can check the server’s response against a given string,
and do some actions depending on the result. In any case, if it matches, this will increment the
match counter, if it does not match, the nomatch counter will be incremented.

For example, let’s say you want to test a login page. If the login is ok, the server will respond
with Welcome ! in the HTML body, otherwise not. To check that:

   <request>
        <match do="continue" when="match">Welcome !</match>
        <http url='/login.php' version='1.0' method='POST'
         contents='username=nic&amp;user_password=sesame'
         content_type='application/x-www-form-urlencoded' >
   </request>

You can use a regexp instead of a simple string.

The list of available actions to do is:

  * continue: do nothing, continue (only update match or nomatch counters)
  * log: log the request id, userid, sessionid in a file (in match.log)
  * abort : abort the session
  * restart: restart the session. The maximum number of restarts is 3 by default.
  * loop: repeat the request, after 5 seconds. The maximum number of loops is 20 by default.
  * dump: dump the content of the response in a file. The filename is match-<userid>-<sessionid>-
    <requestid>-<dumpid>.dump

You can mixed several match tag in a single request:

   <request>
        <match do="loop" sleep_loop="5" max_loop="10" when="match">Retry</match>
        <match do="abort" when="match">Error</match>
        <http url='/index.php' method=GET'>
   </request>

You can also do the action on "nomatch" instead of "match".

If you want to skip the HTTP headers, and match only on the body, you can use skip_headers=’http’.
Also, you can apply a function to the content before matching; for example the following example
use both features to compute the md5sum on the body of a HTTP response, and compares it to a given
value:

  <match do='log' when='nomatch' skip_headers='http'
    apply_to_content='ts_digest:md5hex'>01441debe3d7cc65ba843eee1acff89d</match>
  <http url="/" method="GET" version="1.1"/>

You can also use dynamic variables, using the subst attribute:

  <match do='log' when='nomatch' subst='true' >%%_myvar%%</match>
  <http url="/" method="GET"/>

27 DONE mac install tsung

CLOSED: 2013-04-30 00:23

27.1 brew install tsung

bash-3.2$  brew install tsung
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Downloading http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz
##################################################################################################################################### 100.0%
==> ./configure --prefix=/usr/local/Cellar/tsung/1.4.2
==> make
==> make install

最新文章

  1. 性能测试学习之二 ——性能测试模型(PV计算模型)
  2. 防止系统内存溢出触发OOM的一个内核参数
  3. Spring(五)AOP简述
  4. Android--Intent的使用
  5. hihoCoder-1000-A+B
  6. Inject js code to exchange 2013
  7. linux下查看本机socket端口详细信息
  8. 解读Google分布式锁服务
  9. 如何将C#对象转化为JSON字符串
  10. webx学习1
  11. Python爬虫(八)_Requests的使用
  12. zoj 3602
  13. SSH(Spring Struts2 Hibernate)框架整合(xml版)
  14. python函数(一)调用函数
  15. iOS自动布局的学习
  16. DLLImport的用法C#
  17. 在Plesk安装PHP的Memcached扩展
  18. javascript 中 split 函数分割字符串成数组
  19. JQuery 遮罩层弹窗
  20. A计划(BFS)

热门文章

  1. js 对象类型 (对象的属性 ,对象的方法) this 关键字
  2. webStorm(一)
  3. mac 配置快捷键快速锁屏
  4. asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)
  5. 为什么 把单一元素的数组放在一个struct的尾端问题
  6. DHCP底层参考
  7. linux版本选择
  8. EasyuiAPI:基础
  9. 数学之欧拉函数 &amp;几道poj欧拉题
  10. POJ 2234 Matches Game(取火柴博弈1)