gpt4 book ai didi

java - Resilience4j RateLimiter 似乎忽略配置

转载 作者:行者123 更新时间:2023-12-02 09:04:16 25 4
gpt4 key购买 nike

我对 Resilience4j RateLimiter 有疑问

public static void main(final String[] args) throws InterruptedException {
final ExternalService service = new ExternalService();
final ExecutorService executorService = Executors.newFixedThreadPool(30);

final RateLimiterConfig config = RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(10))
.limitForPeriod(3)
.timeoutDuration(Duration.ofSeconds(12))
.build();

final RateLimiter rateLimiter = RateLimiter.of("RateLimiter", config);

final Callable<Response<String>> callable = RateLimiter.decorateCallable(
rateLimiter, () -> service.get(200, "OK")
);

executorService.submit(callable); //fine in first period
executorService.submit(callable); //fine in first period
executorService.submit(callable); //fine in first period
executorService.submit(callable); //should wait 10 sec and fine in second period
executorService.submit(callable); //should wait 10 sec and fine in second period
executorService.submit(callable); //should wait 10 sec and fine in second period
executorService.submit(callable); //should exit with timeout after 12 seconds
executorService.submit(callable); //should exit with timeout after 12 seconds
executorService.submit(callable); //should exit with timeout after 12 seconds


Thread.sleep(Duration.ofSeconds(40).toMillis());
executorService.shutdown();
}

ExternalService 中,我有一些带有本地时间响应的基本日志记录。我认为它应该像我在评论中解释的那样工作,但我的回应是:

> Task :Main.main()
[12:24:53.5] Return standard response
[12:24:53.5] Return standard response
[12:24:53.5] Return standard response
[12:25:03.5] Return standard response
[12:25:03.5] Return standard response
[12:25:03.5] Return standard response
[12:25:03.5] Return standard response
[12:25:03.5] Return standard response

BUILD SUCCESSFUL in 40s

所以看起来第一个周期很好,但之后,RateLimiter 允许五个下一个线程,并且最后一个线程永远不会被调用。

最佳答案

不幸的是,这是 PR #672 中引入的一个错误,该错误是 v1.2.0 版本的一部分。 PR 增加了每次调用请求多个许可的可能性。该错误现已修复。

关于java - Resilience4j RateLimiter 似乎忽略配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59947739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com