1. Overview
1.1 Plugin Name
- RateLimiter Plugin
1.2 Appropriate Scenario
- traffic control in gateway cluster environment
- rate limiting according to specific rules
- You can set to the interface level, or the parameter level. How to use it depends on your traffic configuration.
1.3 Plugin functionality
- use redis to control gateway traffic
1.4 Plugin code
-
Core Module
shenyu-plugin-ratelimiter. -
Core Class
org.apache.shenyu.plugin.ratelimiter.RateLimiterPlugin -
Core Class
org.apache.shenyu.plugin.ratelimiter.executor.RedisRateLimiter
1.5 Added Since Which shenyu version
- Since ShenYu 2.4.0
1.6 Technical Solution
1.6.1 Using redis token bucket algorithm to limit traffic.
- The system generates the token at a constant rate, and then puts the token into the token bucket.
- The token bucket's capacity. When the bucket is full, the token put into it will be discarded.
- Each time requests come, you need to obtain a token from the token bucket. If there are tokens, the service will be provided; if there are no tokens, the service will be rejected.
- Flow Diagram:

1.6.2 Using redis leaky bucket algorithm to limit traffic.
- water (request) go to the leaky bucket first. The leaky bucket goes out at a fixed speed. When the flow speed is too fast, it will overflow directly (reject service)
- Flow Diagram:

1.6.3 Using redis sliding time window algorithm to limit traffic.
- The sliding time window maintains the count value of unit time. Whenever a requests pass, the count value will be increased by 1. When the count value exceeds the preset threshold, other requests in unit time will be rejected. If the unit time has ended, clear the counter to zero and start the next round counting.
- Flow Diagram:
