Before reading this guide, we assume that you have known simple MQTT and MQTT broker.
EMQ X Broker starts supporting the function rate limit from version V3, including the limit on the PUBLISH packet receiving rate and the TCP data package receiving rate. This article will introduce the use and configuration of this function in detail.
This configuration locate on emqx.conf
:
zone.external.publish_limit = 10,1m
The format of configuration is: <Number>,<Duration>
, which means the maximum number <Number>
of PUBLISH packet that can be allowed to receive during the time <Duration>
.
This configuration locate on emqx.conf
:
listener.tcp.external.rate_limit = 1024,4096
The format of configuration is: <Rate>,<Burst>
, which means the allowed average data package receiving rate is <Rate>
. However, the allowed maximum number is depending on the value of <Burst>
. See the next section for details: rate limit algorithm token bucket-algorithm
This configuration locate on emqx.conf
:
listener.tcp.external.active_n = 100
active_n
actually means that the number of datagrams allowed to be read in the underlying asynchronous I/O. Every time, when the asynchronous read operation reaches this limit, it will be temporarily switched to the Sync mode. Every time, when it switches to the Sync mode, it will check the rate limit one time. Therefore, if the value is larger, the throughput performance of this system is better; if the value is smaller, rate checking is more accurate and the inflow is more stable and the security of the system is higher.
The publish_limit
and rate_limit
we mentioned are implemented by the token bucket algorithm. The algorithm logic is as follows:
burst
at most.rate
.Through token bucket algorithm, we can:
rate
.M
and is greater than rate
, the rate of token decreasing is M - rate
. Therefore, the time for us to take all the tokens from a full bucket is burst / (M - rate)
, and the number of the requests be accepted is burst / (M - rate) * M
during this period.All in all, it can be simply understood as rate
is the average request rate and burst
is is the instantaneous maximum request rate.
Based on the token bucket algorithm, EMQ X's implementation logic for rate limit is as follows:
Its meaning is:
(s - r) / rate
seconds.listener.tcp.external.active_n = 100
listener.tcp.external.rate_limit = 1024,1024000
The above configuration means:
Therefore, users need to set <Burst>
according to the size of the real packet. EMQ X highly recommends that configure it as (max_packet_size * active_n) / 2
to prevent from block.
listener.tcp.external.active_n = 100
zone.external.publish_limit = 10,1m
The above configuration means:
You can transfer <Number>,<Duration>
into the form of <Rate>,<Burst>
, namely <Number> / <Duration>, <Numebr>
.
In addition to the above Rate Limit, it is also supported that perform the following limits for the TCP, WebSocket and other connections:
listener.tcp.external.max_connections = 1024000
The maximum connection number that exists at the same time allowed, namely the maximum number of simultaneous online clients.
listener.tcp.external.max_conn_rate = 1000
The maximum number of concurrent connections allowed per second.
The message retention function of [EMQ X MQTT Broker](https://emqx.io) is implemented by the `emqx_retainer` plugin, which is enabled by default. By modifying the configuration of the` emqx_retainer` plugin, you can adjust the EMQ X Broker's retention message Location, restrict the number of retained messages and maximum payload length, and adjust the expiration time of retained messages.
In March, the focus of our work was on finalising 4.3 release as well as the design of EMQ X Broker 5.0
[MQTT X](https://mqttx.app) is a cross-platform MQTT 5.0 desktop test client provided by the world's leading open source IoT middleware provider [EMQ](https://emqx.io) , which supports macOS, Linux, Windows. The user interface of **MQTT X** simplifies the operation logic of the page with the pattern of chatting software. Users can quickly create multiple simultaneous-online MQTT clients to test the connection/publish/subscribe functions of MQTT/TCP, MQTT/TLS and other MQTT protocol features.