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
- Create a thread group under the test plan.
- Add "MQTT Connection Sampler" (i.e. "MQTT Connect") under the thread group
- Add a "sync timer" under the MQTT connection sampler to ensure all threads start establishing connections at the same time.
- Add "Test Activity" under the thread group to control how long the connection remains after the connection is established.
- Add "MQTT Disconnect Sampler" (ie "MQTT DisConnect") under the thread group to simulate the device being disconnected at the same time.
- Create "Summary Report" and "View Results Tree" listeners under the test plan to check the JMeter request results.
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.
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.
Log in to the EMQX Dashboard page, as shown below:
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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。