-
Notifications
You must be signed in to change notification settings - Fork 30
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
RateLimiter - consider whole operation execution time #251
RateLimiter - consider whole operation execution time #251
Conversation
core/src/main/scala/ox/resilience/DurationRateLimiterAlgorithm.scala
Outdated
Show resolved
Hide resolved
Considering comment.
These changes mean that fixed window behaves in example as specified in the comment. For sliding window consider this example: val rateLimiter = RateLimiter.slidingWindow(3, FiniteDuration(1, "second"), OperationDuration)
forkUserDiscard:
result1 = rateLimiter.runOrDrop(short)
forkUserDiscard:
result2 = rateLimiter.runOrDrop(short)
forkUserDiscard:
result3 = rateLimiter.runOrDrop(long)
forkUserDiscard:
sleep(1500.millis)
result4 = rateLimiter.runOrDrop(instant)
result5 = rateLimiter.runOrDrop(instant)
result6 = rateLimiter.runOrDrop(instant) After 1.5 second, two of three operations ended(at 0.3 seconds, so one full second passed since then), so we should have 2 available permits. Since at this point long operation is still running, we drop last operation and Regarding leakyBucket. I don't know if it makes sense in this mode. It can work like fixed window, where we don't replenish tokens if operation is running, but I can't really wrap my head around if it makes sense. |
core/src/main/scala/ox/resilience/DurationRateLimiterAlgorithm.scala
Outdated
Show resolved
Hide resolved
core/src/main/scala/ox/resilience/DurationRateLimiterAlgorithm.scala
Outdated
Show resolved
Hide resolved
@Kamil-Lontkowski thanks, this looks much better. I left some comments - I think it's especially worthwhile describing how the modified algorithms work (for our future selves :) ), and how they differ from the other mode counterparts. |
And yes, I think the token bucket only makes sense in the original mode |
1078464
to
b48dd23
Compare
Thanks! :) |
Closes #246