小程序
传感搜
传感圈

Getting Started with MQTT Performance Testing: A Primer on Scenarios and Metrics

2023-06-18 06:03:09
关注

Illustration: © IoT For All

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.”

Terms Explanation

MQTT Protocol

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 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.

Typical MQTT Test Scenarios

There are two main test scenarios for MQTT brokers:

  1. Concurrent connection, including concurrent connection numbers and connection rates.
  2. Message throughput, including throughput for message sending and receiving, with some performance-affecting parameters, such as QoS, payload size, and topic wildcard, to simulate the production environment requirements.

The following two aspects must always be considered when designing specific performance test scenarios, especially for PoC or pre-deployment tests:

  1. Simulating usage scenarios in the real production environment as much as possible;
  2. Covering possible peak load.

Test scenarios can be subdivided into the two basic dimensions of connection and message throughput.

#1: Concurrent Connection Testing

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:

  1. Gradually increase concurrent connections at a low connection rate to test system response and resource consumption. This can also determine the maximum concurrency the system can support under given hardware and network resources.
  2. With a fixed number of concurrent connections, test the system’s response and resource consumption at different connection rates.
  3. Differentiate between regular TCP connections and TLS/SSL encrypted connections when designing 1) and 2).

#2: Message Throughput Testing

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:

  1. 1-to-1 symmetric: The number of publishers and subscribers is the same. For each publisher, there is exactly one subscriber to the published topic. In other words, the incoming messages rate is equal to the outgoing rate for the MQTT broker.
  2. Fan-in: A typical IoT applications scenario with many IoT devices acting as publishers, but only a few or a single subscriber, for example, a large number of devices reporting its status or data.
  3. Fan-out: A large number of devices subscribing to one or a few publishers.

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.

Other Scenarios

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.

Performance Metrics

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.

  1. Application system metrics are related to user scenarios and requirements, such as response time (or latency) and concurrency.
  2. Computing resource metrics are related to hardware resource consumption. For MQTT we’re talking about, the metrics are similar to those of other software performance tests, such as CPU, memory, network, and disk I/O.

The MQTT system metrics are closely related to the testing scenario, and the common ones are summarized in the table below.

EMQ Technologies

Wrapping up

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.

Tweet

Share

Share

Email

  • Connectivity
  • IoT Platforms
  • Network and Protocols

  • Connectivity
  • IoT Platforms
  • Network and Protocols

参考译文
入门 MQTT 性能测试:场景与指标简介
图示:© IoT For All 在物联网行业,大量资源受限的传感器和工业控制设备依赖于不可靠且带宽较低的网络。这一现实推动了MQTT在物联网场景中作为理想消息传输协议的流行。因此,MQTT代理确保最佳性能和高可靠性以满足物联网应用的需求显得尤为重要。在对系统进行适当测试之前,了解基本的测试场景和性能指标非常重要。在本文中,我们将基于EMQX团队的测试经验,提供一个全面的解释,这同样适用于所有MQTT代理的测试。“因此,MQTT代理确保最佳性能和高可靠性以满足物联网应用的需求” **术语解释** **MQTT协议** MQTT是Message Queuing Telemetry Transport的缩写。尽管其名称中包含“消息队列”,但它与消息队列毫无关系,而是一种基于发布/订阅模型的轻量级消息协议。凭借其简单性、灵活性、易于实现、支持QoS以及小消息尺寸,MQTT已成为物联网的首选协议。 **性能测试** 性能测试是使用测试工具来模拟各种正常、峰值或异常负载条件,以测试系统各项性能指标的过程。目标是验证系统是否能满足用户的期望,发现系统的性能瓶颈等。 **典型的MQTT测试场景** MQTT代理主要有两个测试场景: 1. **并发连接**,包括并发连接数和连接速率。 2. **消息吞吐量**,包括消息发送和接收的吞吐量,其中一些影响性能的参数,如QoS、负载大小和主题通配符,可用于模拟生产环境的需求。 在设计具体的性能测试场景时,尤其是PoC或预部署测试中,必须始终考虑以下两个方面: - 尽可能模拟真实生产环境的使用场景; - 覆盖可能的峰值负载。 测试场景可细分为连接和消息吞吐量这两个基本维度。 ### #1:并发连接测试 MQTT连接是长(keep-alive)TCP连接。客户端与MQTT代理建立TCP连接,发送MQTT登录请求,然后通过心跳包维持连接。在高并发场景下,建立和保持长MQTT连接会消耗大量代理资源。通过性能测试,我们可以测量MQTT代理在有限资源下能支持多少并发连接。另一方面,连接速率(即每秒新建立的连接数)越高,所需计算资源就越大。在测试中需要特别考虑这一因素,尤其是在大量设备可能同时上线的场景中。该值对于评估系统容量和进行规划至关重要。 并发连接测试中需要考虑的第三个因素是是否使用TLS/SSL加密传输,因为它会消耗额外资源。在测试过程中需要评估其对性能的影响程度。 总结一下,在MQTT并发连接测试中,应考虑以下三个场景: - 以较低的连接速率逐渐增加并发连接,测试系统响应和资源消耗。此方式也可以确定系统在给定硬件和网络资源下可支持的最大并发量。 - 在固定并发连接数下,测试系统在不同连接速率下的响应和资源消耗。 - 设计1)和2)时,区分普通TCP连接和TLS/SSL加密连接。 ### #2:消息吞吐量测试 如前所述,MQTT是一种基于发布/订阅模型的消息传输协议。它是一种异步协议,能实现1对1、1对多和多对1的发布和订阅,广泛应用于各种物联网场景。因此,消息吞吐量测试应包括以下三种场景: - **1对1对称**:发布者和订阅者的数量相同。对于每个发布者,恰好有一个订阅者接收其发布的主题。换句话说,MQTT代理的入站消息速率等于出站速率。 - **汇聚(Fan-in)**:一种典型的物联网应用场景,许多物联网设备作为发布者,但只有少量或一个订阅者。例如,大量设备上报其状态或数据。 - **广播(Fan-out)**:大量设备订阅一到几位发布者。 此外,在设计消息吞吐量场景时,不要忘记QoS、消息负载大小、订阅主题通配符等因素。不同的QoS对性能和负载测试中的资源消耗有显著影响,而负载大小则可根据实际用例确定。 **其他场景** 对于其他MQTT功能,如共享订阅、消息转储到数据库或消息队列、大量主题订阅,以及大量MQTT客户端同时连接/断开的极端情况,也可以根据实际需求计划并纳入测试场景。 **性能指标** 在设计了合适的测试场景后,制定性能指标来衡量测试的成功或失败也非常重要。在性能测试中,指标通常分为两类:应用系统指标(即MQTT代理指标)和计算资源指标。 - **应用系统指标**与用户场景和需求相关,例如响应时间(或延迟)和并发数。 - **计算资源指标**与硬件资源消耗相关。 对于MQTT而言,其指标与其他软件性能测试类似,如CPU、内存、网络和磁盘I/O。MQTT系统指标与测试场景密切相关,常见的指标总结如下表所示。 **EMQ技术总结** 本文讨论了几个典型的测试场景和可用于评估MQTT代理性能的重要指标。通过理解和应用这些测试技术和指标,您可以优化性能和可靠性,提升整体物联网和消息系统基础设施。 **推文分享电子邮件** 连通性、物联网平台、网络与协议 --> 连通性、物联网平台、网络与协议
您觉得本篇内容如何
评分

评论

您需要登录才可以回复|注册

提交评论

广告
提取码
复制提取码
点击跳转至百度网盘