1. 程式人生 > >轉MQTT壓力測試之Tsung的使用

轉MQTT壓力測試之Tsung的使用

all retain doc ctype har mesa nbsp ocs message

轉自: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,一共兩臺機器一起壓。

單臺最大峰值時的連接數截圖:

技術分享圖片

兩臺最大峰值時的連接數截圖:

技術分享圖片

轉MQTT壓力測試之Tsung的使用