Getting Started with MQTT Performance Testing: A Primer on Scenarios and Metrics
EMQ Technologies Inc.EMQ Technologies Inc.
In the IoT industry, a large number of resource-constrained sensors and industrial control devices rely on unreliable and low-bandwidth networks. This reality has propelled the popularity of MQTT as an ideal IoT message transmission protocol for IoT scenarios. Consequently, it becomes crucial for MQTT brokers to ensure optimal performance and high reliability to meet the demands of IoT applications. It's essential to understand the basic testing scenarios and performance metrics before conducting a suitable test for your system. In this blog, we will give a comprehensive explanation based on the testing experience of the EMQX team, which is also applicable to all MQTT brokers testing.
"Consequently, it becomes crucial for MQTT brokers to ensure optimal performance and high reliability to meet the demands of IoT applications."
MQTT stands for Message Queuing Telemetry Transport. Despite its name containing "message queuing," it has nothing to do with message queues. Instead, it is a lightweight messaging protocol based on a publish/subscribe model. With its simplicity, flexibility, easy implementation, support for QoS, and small message size, MQTT has become the preferred protocol for the Internet of Things (IoT).
Performance Testing Performance testing is a process of using testing tools to simulate various normal, peak, or abnormal load conditions to test various performance indicators of the system under-tested. The goal is to verify whether the system can meet the user's expectations, discover performance bottlenecks in the system, and so on.
There are two main test scenarios for MQTT brokers:
The following two aspects must always be considered when designing specific performance test scenarios, especially for PoC or pre-deployment tests:
Test scenarios can be subdivided into the two basic dimensions of connection and message throughput.
MQTT connections are long (keep-alive) TCP connections. The client initiates a TCP connection with the MQTT broker, sends an MQTT login request, and then uses heartbeat packets to sustain the connection. In high-concurrency scenarios, establishing and maintaining long MQTT connections consumes significant resources for the broker. Through performance testing, we can measure how many concurrent connections the MQTT broker can support under limited resources.
On the other hand, the higher the connection rate (i.e., the newly established connections per second), the greater the computing resources required at the same time. It's important to consider this factor during testing, especially in scenarios where numerous devices may come online simultaneously. This value is crucial for evaluating system capacity and planning accordingly.
The third factor to consider in concurrent connection testing is whether to use TLS/SSL encrypted transmission, as it consumes additional resources. It is necessary to evaluate the degree of its impact on performance during testing.
To summarize, in MQTT concurrent connection testing, the following three scenarios should be considered:
As mentioned earlier, MQTT is a message transfer protocol based on the publish/subscribe model. It is an asynchronous protocol that implements 1-to-1, 1-to-many, and many-to-1 types of publishing and subscription, which are widely used in various IoT scenarios. Therefore, message throughput testing should include these three scenarios:
Besides, when designing message throughput scenarios, do not forget QoS, message payload size, subscription topics with wildcards, etc. Different QoS significantly impact performance and resource consumption for load tests. The payload size can be determined based on the actual use cases.
For other MQTT functionalities, such as Shared Subscription, messages dumping to databases or MQ, a large number of topic subscriptions, and extreme situations like numerous MQTT clients connecting/disconnecting simultaneously, these can be planned and incorporated into the testing scenarios based on actual requirements.
After designing a proper testing scenario, it is also important to develop performance metrics to measure the success or failure of the test. In performance testing, the metrics can generally be divided into two categories: application system metrics (here, i.e. MQTT broker metrics) and computing resource metrics.
The MQTT system metrics are closely related to the testing scenario, and the common ones are summarized in the table below.
In this post, we have discussed several typical testing scenarios and important metrics that can be used to evaluate the performance of MQTT brokers. By understanding and applying these testing techniques and metrics, you can optimize the performance and reliability, and improve the overall IoT and messaging system infrastructure.
New Podcast Episode
Recent Articles