Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resilience4j RateLimiter seems to ignore configuration #822

Closed
RobWin opened this issue Jan 28, 2020 · 2 comments
Closed

Resilience4j RateLimiter seems to ignore configuration #822

RobWin opened this issue Jan 28, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@RobWin
Copy link
Member

RobWin commented Jan 28, 2020

Thanks for raising a Resilience4j issue.
Please provide a brief description of your problem along with the versions you are using.
If possible, please also consider putting together a complete JUnit test that reproduces the issue.

Resilience4j version:
1.2.0

Java version:

Problem description:

https://stackoverflow.com/questions/59947739/resilience4j-ratelimiter-seems-to-ignore-configuration

I have a problem with 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();
}

In ExternalService I have some basic logging with localTime of responses. I think that it should work as I explained in comments, but my response is:

> 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

So it seems that the first cycle is good, but after that, FIVE next threads are allowed by RateLimiter, and the last thread is never called.

@RobWin
Copy link
Member Author

RobWin commented Jan 29, 2020

It seems the issue was introduced in PR #672 and release v1.2.0.

@RobWin
Copy link
Member Author

RobWin commented Jan 29, 2020

Fix -> #824

@RobWin RobWin closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants