转自:http://www.cnblogs.com/lingyejun/p/7941271.html
nTsung测试工具的基本测试命令为 Tsung -f ~/.tsung/mqtt.xml -l <日志保存路径> start
mqtt.xml具体如下(在/usr/share/doc/tsung/examples路径下可查找到):
官网文档: http://tsung.erlang-projects.org/user_manual/conf-client-server.html
TSUNG在服务器上的安装步骤
Tsung压测时总连接数 = 本机可用IP地址数量×本机可用端口的数量×远程服务器可访问IP地址数量×远程服务器可访问端口数量。
yum install -y gcc gcc-c++ make libX11 xauth
yum install -y cairo-devel pango-devel freetype-devel gd-devel
yum install -y ncurses-devel openssl-devel unixODBC-devel wxWidgets-devel wxGTK3-docs mesa-libGL-devel wget http://erlang.org/download/otp_src_20.0.tar.gz
wget https://www.cpan.org/modules/by-module/Template/Template-Toolkit-2.26.tar.gz
wget http://tsung.erlang-projects.org/dist/tsung-1.7.0.tar.gz tar zxf otp_src_20.0.tar.gz
cd otp_src_20.0
./configure --prefix=/usr/local/erlang --without-javac
make -j 2
make install tar zxf gnuplot-4.4.2.tar.gz
cd gnuplot-4.4.2
./configure
make -j 2
make install export PATH=$PATH:/usr/local/erlang/bin/
tar zxf tsung-1.7.0.tar.gz
cd tsung-1.7.0
./configure --prefix=/usr/local/tsung
TSUNG的测试脚本
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/tsung/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" version="1.0">
<clients>
<client host="bogon" maxusers="100000" cpu="1">
<ip value="192.168.1.152"></ip>
<ip value="192.168.1.153"></ip>
<ip value="192.168.1.154"></ip>
<ip value="192.168.1.155"></ip>
</client>
</clients> <servers>
<server host="192.168.1.110" port="61613" type="tcp" />
</servers> <load>
<user session="mqtt_subscriber" start_time="30" unit="second"></user>
<arrivalphase phase="1" duration="60" unit="second">
<users maxnumber="100000" arrivalrate="5000" unit="second"/>
</arrivalphase>
</load> <sessions>
<session name="mqtt_publisher" probability="100" type="ts_mqtt">
<request>
<mqtt type="connect" clean_start="true" keepalive="10" username="admin" password="password" will_topic="phihome/test" will_qos="0" will_msg="will_msg" will_retain="false"></mqtt>
</request> <for from="1" to="10" incr="1" var="loops">
<request subst="true">
<mqtt type="publish" topic="phihome/test" qos="1" retained="true">test_message</mqtt>
</request>
</for> <request>
<mqtt type="disconnect"></mqtt>
</request>
</session>
<session name="mqtt_subscriber" probability="0" type="ts_mqtt">
<request>
<mqtt type="connect" clean_start="true" keepalive="10"></mqtt>
</request> <request subst="true">
<mqtt type="subscribe" topic="test_topic" qos="1"></mqtt>
</request> <request>
<!-- wait for 60s -->
<mqtt type="waitForMessages" timeout="60"></mqtt>
</request> <request subst="true">
<mqtt type="unsubscribe" topic="test_topic"></mqtt>
</request> <request>
<mqtt type="disconnect"></mqtt>
</request>
</session>
</sessions>
</tsung>
测试结果总览
注:单台Tsung压测官网纯净版mosquitto(单台Broker),峰值时连接数为197626,后续有追加了另外一台tsung,一共两台机器一起压。
单台最大峰值时的连接数截图:
两台最大峰值时的连接数截图: