Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of MQTT 5.0flow control?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the role of MQTT 5.0flow control". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of MQTT 5.0flow control".

Flow control

Usually, the resources of the server are fixed and limited, while the traffic of the client may change anytime and anywhere. Normal business (centralized access by users, massive restart of devices), malicious attacks, and network fluctuations will all lead to a surge in traffic. If the server does not impose any restrictions on it, it will lead to a rapid increase in load, resulting in a decline in response speed, affecting other businesses, and even paralyzing the system.

Therefore, we need flow control, which can limit the sending rate of the sender or the receiving rate of the receiver, but the ultimate goal is to ensure the stability of the system. The commonly used flow control algorithms are sliding window counting, leaky bucket algorithm and token bucket algorithm.

MQTT v3 does not regulate the flow control behavior, which causes the client and server to let a hundred flowers blossom, thus affecting the access and management of the equipment. Now, however, MQTT v5 has introduced the flow control function, which is what we will discuss next.

Flow Control in MQTT v5

In MQTT v5, the sender has an initial sending quota, which is reduced by one every time it sends a PUBLISH message with a QoS greater than 0, and is increased every time a response message (PUBACK, PUBCOMP, or PUBREC) is received. If the receiver does not respond in time and the sending quota of the sender is reduced to 0, the sender should stop sending all PUBLISH messages whose QoS is greater than 0 until the sending quota is restored. We can think of it as a variant of the token bucket algorithm, and the only difference between them is that the way of increasing the quota is from increasing at a fixed rate to increasing at the rate at which response messages are actually received.

This algorithm can make more active and full use of resources, because it does not limit the sending rate, and the sending rate depends entirely on the response rate and the network condition of the opposite end. If the receiver is idle and the network is good, then the sender can get a higher sending rate, otherwise it will be limited to a lower sending rate.

Receive Maximum attribute

In order to support traffic control, MQTT v5 adds a Receive Maximum attribute, which exists in CONNECT messages and CONNACK messages, indicating the maximum number of PUBLISH packets with QoS of 1 and 2 that the client or server is willing to process at the same time, that is, the maximum sending quota that can be used by the peer. If the number of PUBLISH messages with QoS greater than 0 received but not sent by the receiver exceeds the value of Receive Maximum, the receiver will disconnect to avoid more serious impact.

Why is there no QoS 0?

You may have found that all the previous references to PUBLISH messages use the attribute: QoS is greater than 0. The characteristic of QoS 0 message determines that it does not have response message, maybe it feels that the importance of QoS 0 message is not high, and the receiver can restrict QoS 0 message by forcing the receiving rate limit, maybe it is other reasons. In a word, the flow control mechanism of MQTT v5 is completely dependent on response message, which leads to its flow control can only be limited to QoS 1 # 2 message.

Chat is better than nothing. MQTT v5 offers an imperfect solution, or just a suggestion: when the sending quota is reduced to 0, the sender can choose to continue sending PUBLISH messages with a QoS of 0, or can choose to pause sending. The behavior logic of pausing transmission is that if the response speed of the PUBLISH message of QoS 1 Magi 2 becomes slower, it usually means that the consumption power of the receiver has decreased, and continuing to send QoS 0 messages will only make the situation worse.

Thank you for reading, the above is the content of "what is the role of MQTT 5.0flow control". After the study of this article, I believe you have a deeper understanding of the role of MQTT 5.0flow control, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report