The configuration guide of EMQ X Rate Limit

Configuration items

MQTT PUBLISH packet receiving rate

TCP data package receiving rate

active_ n

Rate limit algorithm — token bucket

Introduction

  1. There is a bucket of a token that can hold up the number of burst at most.
  2. We will add tokens into this bucket at a rate of N per second. If the bucket is full, no more tokens are added to this bucket. We call this rate as rate.
  3. When there are requests, we will take the corresponding number of tokens from the bucket. If the bucket is empty, block it until enough tokens are put in.

Function

  • In the case of running for a long time, the average value of the limited request rate is equal to the rate of adding tokens, the rate.
  • Allow a certain level of peak flow. If the request rate is 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.

The implementation of EMQ X rate limit

  1. The socket performs a rate checking every time it receives n TCP data packets, and will record the total length of the received n TCP data packets as s.
  2. If the number of left tokens in the bucket is greater and equal to s, will update the number of tokens on the corresponding bucket and active_n will be performed through continue activating socket.
  3. If the number of left tokens in the bucket r is less than s, will active socket after waiting for (s - r) / rate seconds.

The example of rate limit configuration

The configuration of rate limit

listener.tcp.external.active_n = 100
listener.tcp.external.rate_limit = 1024,1024000
  • Check the rate every 100 TCP packets are received.
  • The average rate limit is 1024 byte/s.
  • Bucket size is 1000KB. If the total length of this 100 TCP packets is greater than 1000KB, the rate limit will be triggered.
listener.tcp.external.active_n = 100
zone.external.publish_limit = 10,1m
  • Check the rate every 100 TCP packets are received.
  • Only 10 PUBLISH packet will be allowed to receive within one minute.

Other configurations

--

--

--

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Two-way skewed-associative caches

Flutter: Take your badge with you !

Practical DevOps — Continous Integration with Git Vault Talisman

INTRODUCTION TO GRAPHQL

The Next Generation of Infrastructure at TEN7, or “TNG Infra V5”

Run & Deploy Your Microservices Using Project Tye

Access GSuite APIs on your domain using a service account

Why are SMBs Choosing VPS for their Hosting Needs?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.

More from Medium

Apache Tomcat with Nginx Proxy on Ubuntu 20.04

Darkflow-Flask: Object Detection Web App on NVIDIA GPU enabled K8s

Cloud Hypervisor + GDB + Arm64 Part 3: Gap analysis

Multi-Container Apps on User-Defined Networks