Core Module shenyu-plugin-ratelimiter
.
Core Class org.apache.shenyu.plugin.ratelimiter.RateLimiterPlugin
Core Class org.apache.shenyu.plugin.ratelimiter.executor.RedisRateLimiter
rateLimiter
dependency in pom.xml
file of the gateway.<!-- apache shenyu ratelimiter plugin start--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-plugin-ratelimiter</artifactId> <version>${project.version}</version> </dependency> <!-- apache shenyu ratelimiter plugin end-->
shenyu-admin
--> BasicConfig --> Plugin --> rateLimiter
set to enable.mode
: the working mode of redis, the default is single-point mode: standalone
, in addition to cluster mode: cluster
, sentinel mode: sentinel
.
master
: default is master.
url
: configure the IP and port of the redis database, configured by colon connection, example: 192.168.1.1:6379
.
password
: the password of the redis database, if not, you can not configure.
TokenBucket/Concurrent
algorithmName
: tokenBucket
/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.
keyResolverName
: whole
indicates that the traffic is limited by gateway per second, and remoteAddress
indicates that the traffic is limited by IP per second.
LeakyBucket
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.
keyResolverName
: whole
indicates that the traffic is limited by gateway per second, and remoteAddress
indicates that the traffic is limited by IP per second.
SlidingWindow
algorithmName
: slidingWindow
.
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).
keyResolverName
: whole
indicates that the traffic is limited by gateway per second, and remoteAddress
indicates that the traffic is limited by IP per second.
RateLimiter
plugin in gateway cluster environment10.10.10.10:9095
10.10.10.20:9195
and 10.10.10.30:9195
, and config data sync center on 10.10.10.10:9095
upstream shenyu_gateway_cluster { ip_hash; server 10.1.1.1:9195 max_fails=3 fail_timeout=10s weight=50; server 10.1.1.2:9195 max_fails=3 fail_timeout=10s weight=50; } server { location / { proxy_pass http://shenyu_gateway_cluster; proxy_set_header HOST $host; proxy_read_timeout 10s; proxy_connect_timeout 10s; } }
config redis configuration with ratelimiter plugin
config selector
config rule
replenishRate is 3, burstCapacity is 10
Ngin
x by Apache Jmeter
shenyu-admin
--> BasicConfig --> Plugin --> rateLimiter
set Status disable.