`
mryufeng
  • 浏览: 967543 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Writing a Tsung plugin

阅读更多
原文地址:http://www.process-one.net/en/wiki/Writing_a_Tsung_plugin/

Writing a Tsung plugin

This is a simple tutorial on writing a tsung plugin.

Since tsung is used to test servers lets define a simple server for testing. myserver.erl provides 3 operations: echo, add and subtract.

myserver.erl assumes the first byte to be a control instruction followed by 2 or more byte data. The echo operation merely returns the byte data while add and subtract performs these operations on the 2 byte data before returning the results. See the code of myserver.erl for details.

We assume the source files for tsung-1.2.1 are available. This example was compiled using Erlang OTP R11B-3.

Step 0. Download the source code for this tutorial

The source code for this tutorial is available: tutorial_tsung_1.tgz

Step 1. Create tsung configuration file

Based on the 3 operations we want to test we define the myclient.xml which
will take place of tsung.xml. You will notice myclient.xml looks very much
like any normal tsung configuration file. The main difference is in the
session definition. Here we use the ts_myclient type.

<session probability="100" name="myclient-example" type="ts_myclient">
This indicates which plugin tsung should call when creating a server request.
We choose to name this plugin ts_myclient.

The next difference is within the request element. Here we define a ‘myclient’
element indicates the operations to test followed by the relevant data.

Notice that myclient has 2 attributes: type and arith (optional).

Step 2. Update DTD

We now need to modify the tsung-1.0.dtd or validation would fail.

In the request element we add the myclient tag.

<!ELEMENT request ( match*, dyn_variable*, ( http | jabber | raw | pgsql | myclient ) )>
Next we create the myclient element.

<!ELEMENT myclient (#PCDATA) >
Followed by defining the attributes list for myclient.

<!ATTLIST myclient
         arith       (add | sub) #IMPLIED
         type        (echo | compute) #REQUIRED >
Next, we add the ts_myclient option into the element’s type attribute list.

type     (ts_http | ts_jabber | ts_pgsql | ts_myclient ) #IMPLIED
We do the same to the session’s type attribute list.

type         (ts_jabber | ts_http | ts_raw | ts_pgsql | ts_myclient ) #REQUIRED>
Step 3. Create include file

In PATH/include create the include file ts_myclient.hrl.
This include file should have a minimum of two records:

myclient_request: for storing request information parsed from tsung configuration. Will be use to generate server requests.
myclient_dyndata: for storing dynamic information. Not used in this case.
Step 4. Config reader

Create the ts_config_myclient.erl in PATH/src/tsung_controller to parse the XML file. This file must export parse_config/2.
ts_config_myclient:parse_config/2 is called from ts_config:parse/1.

However trying to run ts_config:parse/1 seperately seem to throw an undefined case error.

The important function definition is:

parse_config(Element = #xmlElement{name=myclient}, ...)
Within this pattern we gather the various attributes, echo, compute, add, sub,
and data creating a myclient_request record as needed. Notice for the case
of type compute we parse the data into a list of 2 integers. Ensure you keep
any data manipulation here consistant with calls in ts_myclient:get_message/1.

If your configuration file support several element types then you will need a parse_config function for each.

Step 5. ts_myclient

The final file to create is ts_myclient.erl in PATH/src/tsung.

The get_message/1 function builds the actual data to be transmitted to the server. The function returns a binary even if your protocol uses strings.

In ts_myclient:get_message/1, you can see how we create the message from the myclient_request record. Compare this with myserver:test/3 and myserver:test/1.

parse/2 deals with server responses. It is possible to parse the return data and update monitoring parameters. In the ts_myclient:parse/1 we count the number of single and multi bytes returned from the server. Obviously these must match echo and add / _sub calls.

The ts_mon:add/1 parameters are restricted to:

{count, Type} – increments a running counter
{sum, Type, Val} – adds Val to running counter
{sample_counter, Type, Value} – updates sample_counter
{sample, Type, Value} – updates counter
Step 6. Build and install

Return to PATH and type make followed by make install.

There is no need to update any make files.

Step 7. Running

Start myserver then call myserver:server() in the erlang shell to start listening to the socket.

sh> erl -s myserver start_link
1> myserver:server().
Run tsung, passing it myclient.xml:

sh> tsung -f myclient.xml
Authors

The first version of this tutorial has been written by tty.
分享到:
评论

相关推荐

    tsung用户手册 linux

    压力测试 压力测试 tsung linux

    tsung脚本及说明

    tsung的测试脚本,包含发送单人消息,群组消息,获取花名册等

    Openfire 3.9.3 Load Test Tsung配置xml

    Openfire 3.9.3 Load Test Tsung配置xml,10万用户下集群测试的Tsung压力测试工具的jabber_cluster.xml,session 5分钟

    tsung里面测试websocket的插件

    tsung里面测试websocket的插件含 websocket.xml 等

    Tsung安装使用详细解说

    Tsung安装使用的详细解说,主要针对xmpp的服务端(比如openfire的测试),编写测试场景的脚本配置详细说明。本人使用的是ubuntu操作系统、Tsung1.4.1

    MQTT压力测试之Tsung的使用

    MQTT压力测试之Tsung的使用 MQTT压力测试之Tsung的使用

    tsung+erlang包

    tsung+erlang测试工具,初学者应用必备,内部放置tsung源程序文件和erlang文件

    Tsung_测试XMPP_安装使用说明

    tsung是用erlang开发的一款简单易用的压力测试工具,目前仅支持linux各版本系统安装,有tar.gz和deb两种安装文件, 目前我们测试用的是CentOS或RedHat两种操作系统,因此选择tar.gz安装文件,总的来说tsung工具有...

    tsung测试总结

    tsung 测试 java erlang

    tsung1.6.0

    tsung为一个开源的多协议分布式负载测试工具,使用erlang语言开发的。具体安装使用可以参考URL:http://www.51ste.com/share/det-222.html

    Tsung负载测试tigase

    tsung是一个非常好用的压力测试软件,基于erlang语言,支持多种...在Ubuntu上装好tsung之后,首先要用ulimit修改系统支持的最大fd数量(ulimit-n 20480),否则tsung最多只能创建不到1024个连接,测试脚本是一个xml文件

    tsung安装使用

    关于tsung工具的安装步骤以及使用过程中会遇到的常见问题解答

    tsung高并发测试工具搭建(自己亲测,详细的一逼)

    tsung高并发测试工具搭建(自己亲测,详细的一逼),改文档是自己一步一步摸索出来的,主要是安装tsung整个过程很详细,搭过的人,知道tsung的搭建依赖很恶心,不是一时半会能搞出来的

    tsung最新用户手册

    tsung最新用户手册,包含HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP, and Jabber/XMPP servers压力测试模版,错误说明等。

    tsung安装使用说明

    tsung安装使用,参数说明,模拟openfire注册用户,模拟用户openfire登录、状态更改、发送消息,对openfire长时间压力测试

    tsung安装相关文件

    —tsung-1.5.0.tar.gz —libtemplate-perl_2.20.orig.tar.gz —gnuplot-4.4.0.tar.gz —otp_src_R15B.tar.gz —perl-HTML-Tagset-3.10-2.1.1.noarch.rpm —perl-HTML-Parser-3.55-1.fc6.x86_64.rpm —...

    tigase及tsung安装笔记

    包括tigase的安装运行,tsung的安装运行,压测结果的信息解析等;

    tsung-react-stats:从 json 报告中显示 tsung 统计信息

    tsung-react-stats 从 json 报告中显示 tsung 统计信息

    tsung-1.3.3

    tsung安装包,linux下进行压力测试的工具

    tsung_user_guide

    支持各种协议的压力测试工具,如HTTP/XMPP等

Global site tag (gtag.js) - Google Analytics