Lucas Milotich

02/02/2022, 8:20 PM
Hello guys, maybe someone already went through this: I was looking for a rate limiter with a smooth warm up. I found a Guava Ratelimiter version which is what I want, but it seems to be blocking in some way. I uses a
and a mutex inside therefore I think it won’t be the best solution in a coroutines world (with ktor). I implemented anyways and I’m not finding any blocking or decrease of response time, but I’m getting some errs without load with the reate limiter (under low stress I have false results in
method). I also found resilience4j limiter but it doesn’t have a smooth warm up. Thanks!

Alexis Manin

02/03/2022, 6:43 AM
I do not know if kotlin flows are built this way, but you might look into reactive-stream libraries, because it is one of their core concepts: subscribers of a stream specify the request rate they want. For example, in Spring Reactor, any flux can use the limitRate function : If you need time based rate limiting, you can mix this method with calls to delayed or by zipping an interval flux. There's an extension module to help bind flux and mono objects to coroutines and kotlin flows.