您的位置:首页 > 其它

tsung 分布式压测工具

2015-07-29 21:37 411 查看

一、什么是tsung

最近想整一个分布式压力测试工具,了解到tsung这个工具,感觉还不错,tsung是由erlang编写的分布式压力测试工具,协议还是支持蛮多的,比如HTTP/SOAP等,具体可见官网说明。tsung需要erlang环境,erlang这个语言就不多说了,专门分布式任务设计的一门语言。

二、环境搭建(ubuntu环境)

1. 搭建erlang环境

wget http://erlang.org/download/otp_src_R13B04.tar.gz tar -zxvf otp_src_R13B04.tar.gz
cd otp_src_R13B04/
./configure --prefix=/home/erlang
make
make install</span>


2. 安装erlang环境可能碰到的问题

config.status: creating include/x86_64-unknown-linux-gnu/erl_int_sizes_config.h
*********************************************************************
**********************  APPLICATIONS DISABLED  **********************
*********************************************************************

crypto         : No usable OpenSSL found
jinterface     : No Java compiler found
odbc           : ODBC library - link check failed
ssh            : No usable OpenSSL found
ssl            : No usable OpenSSL found

*********************************************************************
*********************************************************************
**********************  APPLICATIONS INFORMATION  *******************
*********************************************************************

wx             : wxWidgets not found, wx will NOT be usable

*********************************************************************
*********************************************************************
**********************  DOCUMENTATION INFORMATION  ******************
*********************************************************************


(1)若缺少OpenSSL,安装 apt-get install libssl-dev

(2)若缺少ODBC,安装 apt-get
install unixodbc-dev

3. tsung机器之间需要配置SSH互信,这里具体SSH互信配置就不说明了,可见链接

4. 安装tsung,由于笔者的erlang安装目录是/home/erlang,在安装tsung时需要指定erlang的路径

wget http://tsung.erlang-projects.org/dist/tsung-1.4.2.tar.gz tar -zxvf tsung-1.4.2.tar.gz
cd tsung-1.4.2/
<span style="line-height: 21px;">./configure --prefix=/usr/local/tsung --with-erlang=/home/erlang</span>
make
make install</span>


二、tsung配置和启动(笔者使用两台机器,暂且名为node1,node2)

1. 在机器的/etc/hosts需要配置各大节点的 host和ip



2. 启动tsung分布式服务,只需在某个节点配置具体配置文件即可,但需要保证机器之间可以SSH互信和erl、tsung安装路径等一致。笔者打算在node1启动分布式服务,tsung的默认配置文件路径 ~/.tsung/tsung.xml,笔者的配置文件如下:

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/home/erlang/share/tsung/tsung-1.0.dtd">
<!-- set dumptraffic="true" to dump all received and sent packets -->
<!-- set loglevel="debug" for maximum verbosity -->
<tsung loglevel="notice" dumptraffic="false" version="1.0">

<!-- Client side setup -->
<clients>
<!-- maxusers is the max number of simultaneous clients. Don't set
it too high because you can run out of file descriptors. Remember
that ssl_esock use 2 fds by connection. -->

<client host="node1" weight="2" maxusers="500">
<!-- Several virtual IP can be used to simulate more
machines. Very useful when a load-balancer use the client's IP to
distribute the traffic amoung a cluster of servers-->
<ip value="${my node1 ip}"></ip>
</client>

<!-- a second machine is used, with a higher weight, and 2 cpus
(erlang is not SMP aware, so we starts 2 beams to use all the
CPUs -->
<client host="node2" weight="2" maxusers="500">
<ip value="${my node2 ip}"></ip>
</client>

<!-- If you have a single machine to do the tests, you may add
this attribute to the client tag: use_controller_vm="true" . This
will run the virtual users on the same Virtual Machine as the
controller. Useful if you have problems with starting up remote
beam -->

</clients>

<!-- Server side setup -->
<servers>
<server host="${the server you want to request}" port="80" type="tcp"/>
</servers>

<!-- to start os monitoring (cpu, network, memory). Use an erlang
agent on the remote machine or SNMP. erlang is the default -->
<monitoring>
<monitor host="node1" type="erlang"></monitor>
<monitor host="node2" type="erlang"></monitor>
</monitoring>

<!-- several arrival phases can be set: for each phase, you can set
the mean inter-arrival time between new clients and the phase
duration -->
<load>
<arrivalphase phase="1" duration="1" unit="hour">
<users interarrival="2" unit="second"></users>
</arrivalphase>
<arrivalphase phase="2" duration="1" unit="hour">
<users interarrival="1" unit="second"></users>
</arrivalphase>
</load>

<!--  Options. -->
<options>
<!-- Thinktime value overrides those set in the session
nodes if override=true. -->
<option name="thinktime" value="3" random="true" override="false"></option>

<!-- to set specific ssl_ciphers -->
<!--   <default name="ssl_ciphers" value="EXP1024-RC4-SHA,EDH-RSA-DES-CBC3-SHA"></default> -->

<option name="tcp_rcv_buffer"  value="4096"></option>
<option name="tcp_snd_buffer"  value="4096"></option>

<!-- To start ts_file_server. It can be use later in dynamic
substitution using ts_file_server:get_next_line() -->
<!-- <option name="file_server"  value="/root/.tsung/test_file_server.csv"></option>
-->
<!-- HTTP parameters -->

<!-- If you want to benchmark a proxy server instead of a reguler web server-->
<!--   <default type="ts_http" name="http_use_server_as_proxy" value="true"/> -->

<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>
</options>

<!-- ********************************************** -->
<!-- start a session for a http user. the popularity is the
frequency of this type os session. The sum of all session's
popularity must be 100 -->
<!-- ********************************************** -->
<sessions>

<session name="http-example" probability="100" type="ts_http">

<request> <http url="/ok" method="GET" version="1.1"></http> </request>

</session>
</sessions>
</tsung>


3. 启动tsung

tsung start
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: