因为写一个IM的消息通信后台,使用的是netty的websocket来实现,所以需要压测下实际的结果如何。网上查了下发现还是tsung最为强大。可以压测各种场景,还能支持数据和图形界面的结果展示.
一 基本的安装配置
运行环境是依赖于erlang和gnuplot
sudo apt-get install erlang erlang-src gnuplot perl5
包地址下载 :http://tsung.erlang-projects.org/dist/ 我选的是最新的 tsung-1.5.1.tar.gz
tar -zxvf tsung-1.5.1.tar.gz ./configure make sudo make install zhaoming@zhaoming:~/install/soft/tsung/tsung-1.5.1$ tsung Usage: tsung <options> start|stop|debug|status Options: -f <file> set configuration file (default is ~/.tsung/tsung.xml) (use - for standard input) -l <logdir> set log directory where YYYYMMDD-HHMM dirs are created (default is ~/.tsung/log/) -i <id> set controller id (default is empty) -r <command> set remote connector (default is ssh) -s enable erlang smp on client nodes -p <max> set maximum erlang processes per vm (default is 250000) -m <file> write monitoring output on this file (default is tsung.log) (use - for standard output) -F use long names (FQDN) for erlang nodes -w warmup delay (default is 1 sec) -v print version information and exit -6 use IPv6 for Tsung internal communications -x <tags> list of requests tag to be excluded from the run (separated by comma) -h display this help and exit
代表安装成功了
二 运行
将/home/zhaoming/install/soft/tsung/tsung-1.5.1/examples 目录下的websocket.xml复制到~/.tsung/目录下
并根据后面的配置详解中进行修改
zhaoming@zhaoming:~/install/soft/tsung/tsung-1.5.1$ tsung start
Starting Tsung
“Log directory is: /home/zhaoming/.tsung/log/20140609-1510”
所有运行信息都在制定的目录下
三 查看运行结果
cd /home/zhaoming/.tsung/log/20140609-1510 zhaoming@zhaoming:~/.tsung/log/20140609-1510$ /usr/lib/tsung/bin/tsung_stats.pl warn, last interval (5) not equal to the first, use the first one (10) No data for Bosh No data for Match No data for Errors
查看结果
zhaoming@zhaoming:~/.tsung/log/20140609-1510$ firefox graph.html
就会出现图形界面和基本的数据结果
结果数据查看:
1.request :每个请求的响应时间
2.page :一组请求的响应时间
3.connect:连接建立的时间
4.reconnect :重新建立连接数
5.size_rcv :响应的数据大小
6.size_sent :发送的数据大小
7.session :用户在整个会话间的数据
8.users :模拟的用户数
9.connected :已经建立的tcp/udp连接数
10.custom transactions : 消费的事务数
四 配置详解 :
<clients> <client host="localhost" use_controller_vm="true" maxusers="1000" /> </clients>
// 客户端地址,基本不需要修改
<servers> <!-- <server host="10.0.128.147" port="5050" type="tcp" /> --> <server host="localhost" port="5050" type="tcp" /> </servers>
//需要连接的服务器地址
<load> <arrivalphase phase="1" duration="10" unit="minute"> <users interarrival="2" unit="second"></users> </arrivalphase> <arrivalphase phase="2" duration="10" unit="minute"> <users interarrival="1" unit="second"></users> </arrivalphase> <arrivalphase phase="3" duration="10" unit="minute"> <users interarrival="0.1" unit="second"></users> </arrivalphase> </load>
在第一个十分钟,每秒会有2个用户生成
在第二个十分钟,每秒会有一个用户生成
在第三个十分钟,每秒会有10个用户生成
第三个配置等同于
<load> <arrivalphase phase="1" duration="10" unit="minute"> <users maxnumber="100" arrivalrate="10" unit="second"></users> </arrivalphase> </load>
每秒生成10个请求maxnumber是限定了最大不超过100个
unit:可以有second,minute,hour
<sessions> <session name="websocket" probability="100" type="ts_websocket"> <request subst="true"> <websocket type="connect" path="/websocket"></websocket> </request> <request> <websocket type="message" ack="no_ack" frame="text">{type:1,userId:"13588701163"}</websocket> </request> <request> <websocket type="close"></websocket> </request> </session>
name:session名字
probability:发生的概率 100表示100%
type:类型是 websocket
主要是经历三个步骤:connect –> message –> close
一个较为完整的例子
<?xml version="1.0"?> <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" []> <tsung loglevel="notice" version="1.0"> <clients> <client host="localhost" use_controller_vm="true" maxusers="1000" /> </clients> <servers> <!-- <server host="10.0.128.147" port="5050" type="tcp" /> --> <server host="localhost" port="5050" type="tcp" /> </servers> <load> <arrivalphase phase="1" duration="60" unit="second"> <users maxnumber="1200" arrivalrate="20" unit="second" /> </arrivalphase> </load> <sessions> <session name="websocket" probability="100" type="ts_websocket"> <request subst="true"> <websocket type="connect" path="/websocket"></websocket> </request> <request> <websocket type="message" ack="no_ack" frame="text">{type:1,userId:"13588701163"}</websocket> </request> <request> <websocket type="close"></websocket> </request> </session> </sessions> </tsung>
参见文档:http://tsung.erlang-projects.org/user_manual/index.html
0 条评论。