最近在做多服务器之间通信压力测试,找官方TSUNG的手册中也没有发现教程来测试,后来自己胡乱整了一下。实现了2台服务器之间消息通信和状态变更(压力测试,当然如果你只是实现功能测试,手工登录客户端测试2台服务器之间是否通信,就不需要这么麻烦了,需要更多压力就需要修改TSUNG脚本了)
一:测试2台服务器消息互发(即A服务器发聊天消息发送给B中指定的用户)
1.准备2服务器 如:132.159.206.22 和 132.159.206.23 分别部署openfire 服务端
2个服务器对对应的域名分别为
domain address
test6 132.159.206.23
test7 132.159.206.22
2.准备不同的用户登录(主要是不同的用户登录不同的服务器),如我测试的
用户 test1.......test1000,指定登录22 服务器
用户 user1.......user1000,指定登录23 服务器
3.测试数据和程序部署好后启动服务22,23
4.编写TSUNG.xml 测试多服务器通讯
<?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="false"></client> --> <!-- <client host="s207" weight="1" > <ip value="132.159.205.207"></ip> </client> --> <client host="s209" weight="1" > <ip value="132.159.205.209"></ip> </client> <!-- <client host="s209" weight="1" > <ip value="132.159.205.209"></ip> </client> --> </clients> <!-- Server side setup --> <servers> <!-- <server host="132.159.156.143" port="5222" type="tcp"></server> <server host="132.159.206.24" port="5222" type="tcp"></server> --> <!-- <server host="132.159.206.32" port="5222" type="tcp" ></server> <server host="132.159.206.31" port="5222" type="tcp" ></server> --> <server host="132.159.206.23" port="5222" type="tcp" ></server> </servers> <load> <arrivalphase phase="1" duration="5" unit="second"> <users maxnumber="2" interarrival="1" unit="second"></users> </arrivalphase> </load> <!-- <monitoring> <monitor host="s207" type="snmp"/> <monitor host="s207" type="erlang"/> <monitor host="s208" type="erlang"/> <monitor host="s208" type="snmp"/> <monitor host="s209" type="erlang"/> <monitor host="s209" type="snmp"/> </monitoring> --> <!-- JABBER parameters --> <!-- to synchronise users, use a global acknoledgement --> <options> <option type="ts_jabber" name="global_number" value="2"></option> <option type="ts_jabber" name="userid_max" value="2"></option> <option type="ts_jabber" name="domain" value="test6"></option> <option type="ts_jabber" name="username" value="user"></option> <option type="ts_jabber" name="passwd" value="user"></option> </options> <sessions> <session probability="100" name="ba_online" type="ts_jabber"> <request> <jabber type="connect" ack="no_ack"></jabber> </request> <thinktime value="1"></thinktime> <transaction name="authenticate"> <request> <jabber type="auth_get" ack="local"></jabber> </request> <request> <jabber type="auth_set_plain" ack="local"></jabber> </request> </transaction> <transaction name="roster"> <request> <jabber type="iq:roster:get" ack="local"></jabber></request> </transaction> <request> <jabber type="presence:initial" ack="global"/> </request> <thinktime value="1"></thinktime> <transaction name="online1"> <request> <jabber type="raw" ack="no_ack" data="<message to='test3@test7'><body>zhouhui</body> </message>"></jabber> </request> </transaction> <thinktime value="30"></thinktime> <transaction name="close"> <request> <jabber type="close" ack="no_ack"></jabber> </request> </transaction> </session> </sessions> </tsung>
脚本说明 tsung 登录23 服务器 域名为test6 用户是user,设定2个用户登录(即user1,user2) 用户user1,user2登录后会发送给JID test3@test7的用户,其中test7是22服务器域名,test3 是22服务器登陆的用户,即user1,user2会向22服务器上test3用户发送消息,从而达到一台服务跨域发送消息给另一台服务器
脚本关键点:xml 86行<jabber type="raw" ack="no_ack" data="<message to='test3@test7'><body>zhouhui</body> </message>"></jabber>
通过TSUNG RAX xml 加工需要的消息格式
5.验证,用客户端登录22服务器 用户名test3
如图:
6.启动TSUNG 模拟登录23的客户端软件,登录后脚本执行编写好的脚本给test3客户发送2条消息如
这样就可以收到TSUNG跨域发送给另一个服务器客户端的消息了
7. 编写TSUNG.XML 脚本测试更多的用户发送跨域消息了。
二:测试2台服务器用户状态变更(即A服务器状态变更后B服务器收到A服务器用户状态变换)
1.准备2服务器(同上)
2.造测试用户数据
以上1,2同上
3.在openfire中ofrouser表(用户好友表)造跨域的好友数据
如 22 服务器 用户test1 好友user1@test6
23 服务器 用户user1 好友test1@test7
这样每一个用户有一个跨域的好友
4.编写TSUNG.XML
<?xml version="1.0"?> <!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd"> <tsung loglevel="notice" version="1.0"> <clients> <client host="s209" weight="1" > <ip value="132.159.205.209"></ip> </client> </clients> <!-- Server side setup --> <servers> <server host="132.159.206.23" port="5222" type="tcp" ></server> </servers> <load> <arrivalphase phase="1" duration="5" unit="second"> <users maxnumber="1" interarrival="1" unit="second"></users> </arrivalphase> </load> <!-- JABBER parameters --> <!-- to synchronise users, use a global acknoledgement --> <options> <option type="ts_jabber" name="global_number" value="1"></option> <option type="ts_jabber" name="userid_max" value="1"></option> <option type="ts_jabber" name="domain" value="test6"></option> <option type="ts_jabber" name="username" value="user"></option> <option type="ts_jabber" name="passwd" value="user"></option> </options> <sessions> <session probability="100" name="ba_online" type="ts_jabber"> <request> <jabber type="connect" ack="no_ack"></jabber> </request> <thinktime value="1"></thinktime> <transaction name="authenticate"> <request> <jabber type="auth_get" ack="local"></jabber> </request> <request> <jabber type="auth_set_plain" ack="local"></jabber> </request> </transaction> <transaction name="roster"> <request> <jabber type="iq:roster:get" ack="local"></jabber></request> </transaction> <request> <jabber type="presence:initial" ack="global"/> </request> <thinktime value="5"></thinktime> <request> <jabber type="presence:broadcast" show="away" status="Be right back..." ack="no_ack"/> </request> <thinktime value="180"></thinktime> <transaction name="close"> <request> <jabber type="close" ack="no_ack"></jabber> </request> </transaction> </session> </sessions> </tsung>
tsung文档中有一个
<jabber type="presence:broadcast" show="dnd" status="Don't bother me!" ack="no_ack"/>
这段对状态进行广播,受到这个的提示,在ofrouser表中事先造好好友数据。这样通过该脚本广播,当1台机器上用户状态变更,另1台机器对应该用户的好友状态也随之变更,达到测试的目的
5.验证,用客户端登录22服务器 用户名test3
6.启动TSUNG 模拟登录23的客户端软件,登录后脚本执行编写好的脚本给test3客户发送状态变更,截图同上面类似。
7.几个用户验证脚本正确,这样修改脚本最大用户数,测试大量用户状态变更。