Home > study > 来点压力——tsung

来点压力——tsung

May 13th, 2008 :: jackyz

昨日四川发生7.8级大地震,灾情陆续传来,在此,先向死难的同胞们默哀。。。。

最近用上了 Tsung ,传说中“压垮了N台服务器”的 download midi ringtones nickelback ringtones cell phone ringtones virgin mobile usa ringtones download nokia ringtones samsung polyphonic ringtones ericsson polyphonic ringtones sony free real tone ringtones free nextel ringtones ringtones composer free ringtones and wallpaper for cell phone download free ringtones virgin mobile 1600 nokia ringtones cell cingular free phone ringtones christian download free ringtones free real ringtones sprint free nokia mp3 ringtones cingular free phone ringtones sony ericsson ringtones download free ringtones t mobile Erlang 压力测试工具啊。在这里记一下流水帐。

安装

获取tsung 的源码

wget http://www.process-one.net/downloads/tsung/1.2.2/tsung-1.2.2.tar.gz; tar -zxvf tsung-1.2.2.tar.gz

svn co http://svn.process-one.net/tsung/trunk

确保依赖关系
tsung 依赖了这些东西 erlang(废话,从源码编译 erlang 写的程序,能不装么) gnuplot perl5(如果想看 report 中的图形,就要装这个),将其一一装上。

apt-get install erlang erlang-src gnuplot perl5

编译安装

./configure
make
sudo make install

安装完成之后的 tsung 运行脚本在 /usr/bin/tsung ,在系统 path 之中,可以直接运行。

设置

从 /usr/share/doc/tsung/examples 中挑一两个例子拷贝到 ~/.tsung/tsung.xml 作为配置文件。我只需要 http 测试,所以:

cp /usr/share/doc/tsung/examples/http_simple.xml ~/.tsung/tsung.xml

tsung 采用了巧妙的 proxy 方式来“录制”测试脚本。具体来说,就是建立一个本机的 http proxy 默认使用 8090 端口,在配好 firefox 使用 localhost 8090 作为代理之后(推荐 foxyproxy 插件),所有“流经”这个 proxy 的 http 动作都会被记录下来,测试时可以“回放”这些步骤来产生请求。

tsung rocorder
tsung stop_recorder

“录制”完了,会得到一个 ~/.tsung/tsung_recorderXXXXXXXXXX.xml 文件,这就是测试时回回放的脚本。

将这个脚本加到 tsung.xml 之中

gedit ~/.tsung/tsung.xml

就像这样

<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" [
 <!
ENTITY mysession1 SYSTEM "/home/yourname/.tsung/tsung_recorderXXXXXXXXXX.xml">
]>
...
<sessions>
 
&mysession1;
</sessions>

对配置稍作调整

<monitoring>
    
<monitor host="localhost" type="erlang"></monitor>
 
</monitoring>
 
<!-- 需要配置到 localhost 无须密码的 ssh 登录(ssh via rsa_key),开启了这个配置可以,获得目标机器的 cpu 和 ram 消耗情况 -->
 
<load>
  
<arrivalphase phase="1" duration="1" unit="minute">
    
<users interarrival="2" unit="second"></users>
  
</arrivalphase>
 
</load>
 
<!-- 第1阶段1分钟(你可以自己多搞几个阶段),其中每2秒新建一个用户,每个用户都会完整执行 session 的测试脚本,最高并发约为 30 个,个人认为这个“逐渐加压”的方法比 ab xxxx 的“突然加压”要慢一些,但更科学一点 -->

运行

准备好了,加压运行。

tsung start

运行完,在 ~/.tsung/log 目录会生成一个以时间命名的目录,进入这个目录

cd ~/.tsung/log/xxxxx
/usr/lib/tsung/bin/tsung_stats.pl

生成 html 的压力测试报告

firefox report.html

慢慢欣赏吧。

除了 http 以外 tsung 还可以压很多东西,比如:jabber, postgreSQL 还可以写插件来给任何你想要测试的东西加压,配置文件也很“丰富多彩”,更多的内容情看文档。

注,以上内容在 ubuntu 8 下整理,其他平台,请自行探索。

study

  1. newman
    December 16th, 2008 at 12:06 | #1

    你好!
    我最近也在用Tsung来测试jabber server
    但不明白这个recorder 过程怎样录制?
    >tsung recorder
    Error in process on node
    >tsung stop_reocrder ##显示如下错误
    Error in process on node ‘killer@hostname’ with exit value: {badarg,[{erlang,list_to_existing_atom,["ejabberd@localhost"]},{dist_util,recv_challenge,1},{dist_util,handshake_we_started,1}]}

    能帮忙分析下马?
    谢谢!

  2. jackyz
    December 16th, 2008 at 20:52 | #2

    got no clue,俺没试过用 tsung 对 jabber 作压力测试。

  3. Rocky
    January 13th, 2009 at 10:09 | #3

    Tsung Manual:4.5.1 (1) said: There’s no record for jabber
    后面也有提到:如果想手写jabber的record, 可以参考6.6.3

  4. sunny
    March 18th, 2009 at 15:27 | #4

    对于jabber,没有recorder,需要自己手动写.可以参照tsung/example/下面的例子.

    LZ,关于tsung的并发,我不是很理解。测试http时,每个用户都会去执行session.有的用户刚开始执行,有的用户就已经结束了.怎样在这里做好平衡.谢谢!

  5. kali
    November 9th, 2009 at 11:15 | #5

    @newman
    Hi Newman, sorry my chinese: I had the same problem and I solved by properly setting up the machine’s hostname. Check the output of the command ‘hostname -s’. Good luck!
    —————-

    您好,对不起,我的中文纽曼:我有同样的问题,我通过正确的设置了机器的主机解决。检查命令的输出’hostname -s’的。祝您好运!

  1. July 14th, 2010 at 17:47 | #1