replenishRate 和 burstCapacity 有什么区别?
What is the difference between replenishRate and burstCapacity?
在 Redis 的 RequestRateLimiter 实现中,我们必须指定两个属性 redis-rate-limiter.replenishRate
和 redis-rate-limiter.burstCapacity
作为 RequestRateLimiter 过滤器的参数。
根据 documentation,
The redis-rate-limiter.replenishRate
is how many requests per second
do you want a user to be allowed to do, without any dropped requests.
This is the rate that the token bucket is filled.
The redis-rate-limiter.burstCapacity
is the maximum number of requests
a user is allowed to do in a single second. This is the number of
tokens the token bucket can hold. Setting this value to zero will
block all requests.
据我所知,replenishRate
是发出请求的速率,burstCapacity
是可以发出的最大 请求(均在一秒内)。
但是,我似乎无法理解两者在实际场景中的区别。
不同的时间单位更容易掌握,例如:
- 补充率:每分钟 1000 个请求
- 突发容量:每秒 500 个请求
前者控制您在一分钟内永远不会收到超过 1000 个请求,而 后者允许您在同一秒内支持最多 500 个请求的临时负载峰值。您可能在第 0 秒有一个 500 的突发,在第 1 秒有另一个 500 的突发,并且您将达到速率限制(同一分钟内有 1000 个请求),因此接下来的 58 秒内的新请求将被丢弃。
在 Spring 云网关 (SCG) 的上下文中,文档有点模棱两可 (the rate limiter needs to be allowed some time...
):
A steady rate is accomplished by setting the same value in
replenishRate and burstCapacity. Temporary bursts can be allowed by
setting burstCapacity higher than replenishRate. In this case, the
rate limiter needs to be allowed some time between bursts (according
to replenishRate), as two consecutive bursts will result in dropped
requests (HTTP 429 - Too Many Requests).
从前面的例子推断,我会说 SCG 是这样工作的:
- 补充率:每秒 1000 个请求
- 突发容量:每秒 2000 个请求
您可以在同一秒(秒 0)内突发(峰值)2000 个请求。由于您的补给率为 1000 rps,您已经超过了两个周期的限额,因此您要等到第 3 秒才能发送另一条消息。
在 Redis 的 RequestRateLimiter 实现中,我们必须指定两个属性 redis-rate-limiter.replenishRate
和 redis-rate-limiter.burstCapacity
作为 RequestRateLimiter 过滤器的参数。
根据 documentation,
The
redis-rate-limiter.replenishRate
is how many requests per second do you want a user to be allowed to do, without any dropped requests. This is the rate that the token bucket is filled.The
redis-rate-limiter.burstCapacity
is the maximum number of requests a user is allowed to do in a single second. This is the number of tokens the token bucket can hold. Setting this value to zero will block all requests.
据我所知,replenishRate
是发出请求的速率,burstCapacity
是可以发出的最大 请求(均在一秒内)。
但是,我似乎无法理解两者在实际场景中的区别。
不同的时间单位更容易掌握,例如:
- 补充率:每分钟 1000 个请求
- 突发容量:每秒 500 个请求
前者控制您在一分钟内永远不会收到超过 1000 个请求,而 后者允许您在同一秒内支持最多 500 个请求的临时负载峰值。您可能在第 0 秒有一个 500 的突发,在第 1 秒有另一个 500 的突发,并且您将达到速率限制(同一分钟内有 1000 个请求),因此接下来的 58 秒内的新请求将被丢弃。
在 Spring 云网关 (SCG) 的上下文中,文档有点模棱两可 (the rate limiter needs to be allowed some time...
):
A steady rate is accomplished by setting the same value in replenishRate and burstCapacity. Temporary bursts can be allowed by setting burstCapacity higher than replenishRate. In this case, the rate limiter needs to be allowed some time between bursts (according to replenishRate), as two consecutive bursts will result in dropped requests (HTTP 429 - Too Many Requests).
从前面的例子推断,我会说 SCG 是这样工作的:
- 补充率:每秒 1000 个请求
- 突发容量:每秒 2000 个请求
您可以在同一秒(秒 0)内突发(峰值)2000 个请求。由于您的补给率为 1000 rps,您已经超过了两个周期的限额,因此您要等到第 3 秒才能发送另一条消息。