为什么 RateLimiter 在 2 TPS 的速率限制下只允许 1 笔交易?

Why does RateLimiter allow only 1 transaction for a rate limit of 2 TPS?

为 2 TPS 的速率配置的 RateLimiter 仅允许第一个请求并限制第二个请求。

import com.google.common.util.concurrent.*;

class Main {

    public static void main(String... args) {
        RateLimiter rl = RateLimiter.create(2);
        System.out.println(rl.getRate());
        System.out.println(rl.tryAcquire());
        System.out.println(rl.tryAcquire());
        System.out.println(rl.tryAcquire());
   }

}

输出:

2.0
true
false
false

我预计由于速率配置为 2 TPS,它将允许前 两个 请求,而不仅仅是第一个。为什么会这样?

使用 guava-27.0-jre.jar.

感谢任何帮助。

平滑分布

A RateLimiter is defined primarily by the rate at which permits are issued. Absent additional configuration, permits will be distributed at a fixed rate, defined in terms of permits per second. Permits will be distributed smoothly, with the delay between individual permits being adjusted to ensure that the configured rate is maintained.
It is possible to configure a RateLimiter to have a warmup period during which time the permits issued each second steadily increases until it hits the stable rate.

参考:Rate Limiter

配置的速率在时间间隔内均匀分布。 (更像是滑动window)