`
mryufeng
  • 浏览: 982398 次
  • 性别: 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安装使用详细解说

    本文将详细讲解在Ubuntu系统上安装Tsung 1.4.1,并针对Openfire服务端进行压力和性能测试的过程。 ## 1. Tsung安装 ### 1.1 Tsung运行环境安装 在开始安装Tsung之前,确保系统已经安装了Erlang环境。Erlang是...

    tsung里面测试websocket的插件

    1. **安装Tsung**:首先确保系统已经安装了Tsung,如果没有,可以从官方仓库或通过包管理器进行安装。 2. **配置`websocket.xml`**:根据实际的WebSocket服务和测试需求,编辑配置文件。 3. **运行测试**:使用Tsung...

    tsung1.6.0

    **Tsung 1.6.0 - 开源多协议分布式负载测试工具** Tsung是一个功能强大的、基于Erlang编程语言开发的开源负载测试工具。它设计用于模拟大量用户并发访问,以测试网络服务和系统的性能及稳定性。Tsung不仅支持HTTP、...

    MQTT压力测试之Tsung的使用

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

    tsung+erlang包

    **Tsung + Erlang 包详解** Tsung 是一个开源的多协议负载和性能测试工具,它可以模拟大量用户并发访问服务器,从而评估系统的负载能力和稳定性。Tsung 的设计目标是提供一个灵活、可扩展的解决方案,能够测试各种...

    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测试总结

    ### TSUNG测试总结 #### 一、TSUNG概述 TSUNG是一款开源的负载与压力测试工具,主要用于评估系统的性能及稳定性。它支持多种协议,包括但不限于XMPP、HTTP、MySQL等,并且具备支持集群和高效运行的特点。由于其...

    Tsung_测试XMPP_安装使用说明

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

    tsung最新用户手册

    Tsung是一款开源的压力测试工具,能够模拟多个用户对各种服务器应用进行压力测试。它使用Erlang语言编写,支持多种协议,如HTTP、WebDAV、SOAP、PostgreSQL、MySQL、LDAP和Jabber/XMPP。在实际使用中,Tsung可以模拟...

    Tsung负载测试tigase

    ### Tsung负载测试Tigase知识点详解 #### Tsung概述 Tsung是一款高效的压力测试工具,采用Erlang语言开发,能够支持多种网络协议,包括XMPP、HTTP、MySQL等。其独特的分布式特性使得它能够在单机环境下模拟大量...

    tsung安装使用

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

    tsung安装使用说明

    ### Tsung 安装与使用详解 #### 一、Tsung 概述 Tsung 是一款基于 Erlang 开发的高性能压力测试工具,主要用于评估系统的并发处理能力。它支持多种协议,包括 HTTP、WebDAV、Jabber/XMPP、PostgreSQL、LDAP 和 ...

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

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

    tsung_user_guide

    ### Tsung用户指南知识点概述 #### 一、引言 ##### 1.1 Tsung是什么? Tsung是一款开源的压力测试工具,它能够模拟大量用户并发访问应用系统,并收集详细的性能数据,帮助用户评估系统的可扩展性和性能瓶颈。...

    tsung-1.3.3

    **Tsung 1.3.3:Linux环境下的强大压力测试工具** Tsung是一个高度可扩展、分布式的多协议负载和性能测试工具,专为模拟大量用户并发访问系统而设计。它支持多种网络协议,包括HTTP、HTTPS、FTP、TCP、UDP、jabber/...

    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 —...

    tsung-1.5.1.tar.gz

    【tsung-1.5.1.tar.gz】是一款开源的压力测试工具,专为评估系统在高负载下的性能和稳定性而设计。它具有广泛的应用场景,特别是在测试分布式系统,如即时通讯服务器Openfire时表现尤为出色。这个压缩包包含了Tsung...

    tigase及tsung安装笔记

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

Global site tag (gtag.js) - Google Analytics