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

tsung: an open-source multi-protocol distributed load testing tool的更多相关文章

  1. Difference Between Performance Testing, Load Testing and Stress Testing

    http://www.softwaretestinghelp.com/what-is-performance-testing-load-testing-stress-testing/ Differen ...

  2. Jmeter Distributed (Remote) Testing: Master Slave Configuration

    What is Distributed Testing? DistributedTestingis a kind of testing which use multiple systems to pe ...

  3. [Windows Azure] Load Testing in Windows Azure

    The primary goal of a load test is to simulate many users accessing a web application at the same ti ...

  4. Load Testing Socket.IO Web Applications and Infrastructure

    转自:https://medium.com/better-programming/load-testing-socket-io-web-applications-and-infrastructure- ...

  5. Codeforces 847H - Load Testing

    847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  6. Locust - A modern load testing framework https://locust.io/

    Locust - A modern load testing frameworkhttps://locust.io/

  7. Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...

  8. Apache JMeter - load test tool

    What is it? ->>>> http://jmeter.apache.org/index.html  (Please read!) Where to get it? - ...

  9. 九款Web服务器性能压力测试工具

    一.http_load 程序非常小,解压后也不到100Khttp_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会 ...

随机推荐

  1. 对比git pull和git pull --rebase

    1.使用下面的关系区别这两个操作:git pull = git fetch + git mergegit pull --rebase = git fetch + git rebase 2 一.基本 g ...

  2. Uploadifive 使用教程【结合七牛】

    Uploadify是一个基于JQuery的多文件上传JS组件,高度定制,两个版本可供选择.flash版本在最新的Safari等不再支持flash的浏览器或者一些手机浏览器中就无法正常的加载使用,因此推 ...

  3. linux共享文件夹

    mnt中没有 hgfs,重新安装vm tools后问题解决

  4. Javaweb 第15天 web练习和分页技术

    第15天 web练习和分页技术 复习day14内容: 学习新技术的思路? 分析功能的思路? 使用queryRunner操作数据库的步骤? ResultSetHandler接口常用实现类(三个重点)? ...

  5. AuthenticationManager, ProviderManager 和 AuthenticationProvider

    AuthenticationManager是一个接口: public interface AuthenticationManager { Authentication authenticate(Aut ...

  6. 点(.)运算符和箭头(->)运算符的区别

    本机中,char类型数据占用1byte, unsigned int, int, long int, float类型的数据占用4 bytes, double类型的数据占用8bytes. 至于指向所有基本 ...

  7. MVC3+EF4.1学习系列(六)-----导航属性数据更新的处理

    通过上一篇的学习 我们已经知道怎么查询关系 这篇就来说说怎么导航属性数据更新时的处理 以及EF又会为我们生成哪些SQL~ 老规矩 先看下今天的图 添加和修改页面基本就是这样 这节的内容相对简单~~ 主 ...

  8. SignalR的坑爹细节

    好吧!SignalR的确是好用,照着官网的例子自己敲了一遍,死活得不到效果... 检查了半天,抱着试一试的心态吧原来在服务端大写开头的Hub类和大写开头的方法在客户端调用的时候,全部改成小写,一刷新, ...

  9. Java "==" 和 "equals" 和 "" 问题

    //equals()方法出现的问题 String a="testd"; String b="testd"; String c=new String(" ...

  10. Gentoo本地化设置--Locale系统介绍

    locale是什么? 一份Locale是一组信息的集合,大多数程序利用它来确定特定的国家和语言设置.这些locale以及它们包含的数据是系统库的一部分,可以在大多数系统中的/usr/share/loc ...