【问题标题】:Resilience4j RateLimiter seems to ignore configurationResilience4j RateLimiter 似乎忽略了配置
【发布时间】:2020-02-03 16:31:21
【问题描述】:

我对 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 中,我有一些带有localTime 响应的基本日志记录。我认为它应该像我在 cmets 中解释的那样工作,但我的回应是:

> 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 允许五个下一个线程,并且永远不会调用最后一个线程。

【问题讨论】:

  • 我正在调查它。我创建了一个问题来跟踪它。 github.com/resilience4j/resilience4j/issues/822
  • @RobertWinkler 您现在可以提供答案吗?我看到这个问题已经解决了
  • 是的,不幸的是,这是一个在 PR 中引入的错误,它是 1.2.0 版的一部分。 PR 增加了每次调用请求多个许可的可能性。该错误现已修复。
  • 请在此处添加答案,以便我关闭它:)

标签: java multithreading java-8 executorservice resilience4j


【解决方案1】:

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

【讨论】:

  • 不幸的是,在 1.3.1 版本中,这仍然无法正常工作。对于前 6 个调用,它工作正常,但其余 3 个没有抛出异常
猜你喜欢
  • 1970-01-01
  • 2015-10-11
  • 2013-09-12
  • 2020-07-08
  • 2020-03-29
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2016-09-30
相关资源
最近更新 更多