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. Layui文件上传样式在ng-dialog不显示的问题处理

    1.项目业务改动,在一个弹窗页面加图片上传. 2.页面使用angular框架,图片上传使用layui的文件上传组件. js: layui.upload({ url: '/test/upload.jso ...

  2. Nohttp框架在Android Studio中的使用

    1.添加noHttp的使用权限 <!-- 读写 sd 卡 --> <uses-permission android:name="android.permission.REA ...

  3. 郑州尚学堂:如何看待ARM的各种模式?

    嵌入式设备已经越来越与我们的日常生活密切相关了,由此带来了ARM的高速发展.就拿我们的手机来说吧,几乎所有的手机都是ARM体系的.这里大致介绍下ARM 的7种执行模式. ARMv4以上版本的CPU任何 ...

  4. XSL相关

    <?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet type="tex ...

  5. Xcode-之Code Snippets Library

    一.说明 Code Snippets Library 为代码片段库,在开发项目过程中经常会遇到一些重复的代码块,创建代码片段库可以减少我们开发的工作量,而且非常方便调用.Xcode系统中也为我们提供了 ...

  6. PHP命名空间(Namespace)的使用详解

    对于命名空间,官方文档已经说得很详细[查看],我在这里做了一下实践和总结. 命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只 ...

  7. iOS开发中怎么样使用激光推送

    1.注册激光推送的账号 ----> 创建应用 2.上传推送测试和发布的p12文件  注意密码的填写 3.下载sdk并拖进工程里 4.在build setting 搜索search   把路径改一 ...

  8. 《JS权威指南学习总结--开始简介》

    本书共分成了四大部分: 1.JS语言核心 2.客户端JS 3.JS核心参考 4.客户端JS核心参考 其中 <JS权威指南学习总结--1.1语法核心> 是:第一部分JS语言核心 各章节重点 ...

  9. 【Python】生成器和递归

    l=[1, 2, 3, 4, 5, 6] 如果l求和,毫无疑问可以使用递归,比如可以这样: def sum(l): res = 0 for i in l: if not isinstance(i, l ...

  10. 付款前.检查状态.防止重复付款,需要ajax设置为同步,等待ajax返回结果再使用

    $("#surePay").on("touchstart",function(){ var apply_id = $('#apply_id').val(); v ...