Hello guys, maybe someone already went through thi...
# server
l
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
synchronized
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
tryAcquire
method). I also found resilience4j limiter but it doesn’t have a smooth warm up. Thanks!
a
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 : https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html#limitRate-int-int- 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.