Through the previous articles, I believe that you are already familiar with the basic knowledge of JMeter and the use of MQTT plug-ins. From the beginning of this article, we use these test tools to test the actual combat. This article will cover testing of MQTT connections.

Connection Scenario Analysis

The MQTT Connect request in the plug-in mainly simulates the establishment of a connection between the device and the MQTT server (this article takes EMQX as an example), and sends MQTT keep alive messages at specified intervals. In actual IoT scenarios, a large number of devices are often connected and kept online. Devices go online and offline at the same time; the script in this article will simulate 400 devices to establish a connection with EMQX at the same time, and keep the connection for 30 minutes and then go offline at the same time.

How to write test scripts using the MQTT plugin

  1. Create a thread group under the test plan.
    JMeter 创建线程组
  2. Add "MQTT Connection Sampler" (i.e. "MQTT Connect") under the thread group
    JMeter 添加 MQTT 连接采样器
  3. Add a "sync timer" under the MQTT connection sampler to ensure all threads start establishing connections at the same time.
    JMeter 添加同步定时器
  4. Add "Test Activity" under the thread group to control how long the connection remains after the connection is established.
    JMeter 添加测试活动
  5. Add "MQTT Disconnect Sampler" (ie "MQTT DisConnect") under the thread group to simulate the device being disconnected at the same time.
    JMeter 添加 MQTT 断开连接采样器
  6. Create "Summary Report" and "View Results Tree" listeners under the test plan to check the JMeter request results.
    JMeter 汇总报告
    JMeter 察看结果树

execution of tests

Debug and verify the prepared script, and after confirming that the connectivity of the MQTT Broker and the script running logic are as expected, change the number of thread groups on the thread group page to 400, and click the Start button on the page to execute the test.
JMeter Start

Looking at the connection results, the aggregated report shows that the throughput is 394.9/s, that is, 400 clients connect simultaneously within 1 second.
JMeter 汇总报告2

JMeter 查看采样器结果

Log in to the EMQX Dashboard page, as shown below:

EMQX Dashboard

Attachment: Sample Script

Readers can download the test script run and view the results.

Copyright statement: This article is original by EMQ, please indicate the source when reprinting.

Original link: https://www.emqx.com/zh/blog/test-mqtt-connection-with-jmeter


EMQX
336 声望436 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...