dev_dj
dev_dj

Reputation: 1

What should be executor thread pool size while using Guava Rate limiter of 5 permits per second?

I created an Executor with fixed thread pool size of 50 when I had to process 1500 tasks in total using guava rate limiter(5 permits/second). But I still got 429 for some tasks. Tasks mean calling 3rd Party API.

How can I make strictly 5 calls per second to third party API?

Upvotes: 0

Views: 420

Answers (1)

Oscar Besga Panel
Oscar Besga Panel

Reputation: 25

I had similar problemas, I would use Bucket4J

https://bucket4j.com/

Create

            Bandwidth limit = Bandwidth.classic(permitsPerSecond,
                Refill.intervally(permitsPerSecond, Duration.ofSeconds(1L)));
        Bucket bucket = Bucket.builder().
                addLimit(limit).
                build();

then

bucket.tryConsume()

or

bucker.asBlocking().consume()

Hope it helps

Upvotes: 0

Related Questions