Rate limit

    Rate limit is a backpressure scheme that avoids system overload from the entrance and guarantees system stability and predictable throughput. The rate limit can be configured in :

    • max_conn_rate is the rate limit for connection establishment on a single emqx node. 1000 means that 1000 clients can access at most.
    • conn_messages_in is the rate limit for receiving PUBLISH packets on a single connection. means that the maximum PUBLISH message rate allowed on each connection is 100 every 10 seconds.

    and conn_bytes_in both provide limits for a single connection. EMQX Broker currently does not provide a global message rate limit.

    EMQX Broker uses the algorithm to control all Rate Limits. The logic of the token bucket algorithm is as follows:

    • There is a bucket that can hold the maximum burst of the token. The maximum burst is abbreviated as b.
    • There is a rate for adding tokens to the bucket per second, abbreviated as r. When the bucket is full, no tokens are added to the bucket.
    • Whenever 1 (or N) request arrives, take 1 (or N) token from the bucket. If the token is not enough, it will be blocked and wait for the token to be generated.

    It can be seen from this algorithm:

    • In the long run, the average value of the limited request rate is equal to the value of rate.

    When the following configuration is used for packet rate limiting:

    EMQX Broker will initialize the rate-limit processor of each connection with two values:

    • rate = 100 KB / 10s = 10240 B/s
    • burst = 100 KB = 102400 B

    According to the algorithm in , it is known:

    • In the long run, the allowable average rate is limited to 10240 B/s
    • The allowable peak rate is 102400 + 10240 = 112640 B/s
    Configuration itemTypeDefault valueDescription
    listener.tcp.external.active_nNumber100how many messages are read from the TCP stack by emqx at a time