rateLimiter is core implementation of gateway restrictions on network traffic.
The soul gateway provides a variety of current limiting algorithms, including token bucket algorithm
, concurrent token bucket algorithm
, leaky bucket algorithm
and sliding time window algorithm
.
The implementation of current limiting algorithm of soul gateway is based on redis
.
You can set to the interface level or the parameter level. How to use it depends on your traffic configuration.
In soul-admin
--> plugin management--> rate_limiter
set to enable.
Configure redis in the plugin.
Currently, supporting redis patterns of single, sentinel, and cluster.
If it is a sentinel, cluster and other multi-node configuration in URL, please use ;
for each instance; Division. For example, 192.168.1.1:6379; 192.168.1.2:6379。
If the user don't use, please disable the plugin in the background.
rateLimiter
dependency in pom.xml file of the gateway.<!-- soul ratelimiter plugin start--> <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-plugin-ratelimiter</artifactId> <version>${last.version}</version> </dependency> <!-- soul ratelimiter plugin end-->
Selectors and rules, please refer to: selector。
Detailed description of the rules
lgorithmName:tocketBucket/concurrent
replenishRate:It is how many requests you allow users to execute per second, while not discarding any requests. This is the filling rate of token bucket.
burstCapacity:it is the maximum number of requests that users are allowed to execute in one second. This is token bucket can save the number of token.
algorithmName:leakyBucket
replenishRate:The rate at which requests are executed per unit time, and the rate at which water droplets leak out of the leaky bucket.
burstCapacity:The maximum number of requests that users are allowed to execute in one second. This is the amount of water in the bucket.
algorithmName:sildingWindow
replenishRate:The rate of requests per unit time, used to calculate the size of the time window.
burstCapacity:The maximum number of requests in the time window (per unit time).