Which throttling implementation to use? [closed]
Asked Answered
M

0

7

I'm implementing a throttling mechanism to limit the amount of web requests sent to a server. If there are too many submissions for a request then the extra requests are queued until the resource becomes available. There seems to be many throttling options and im not sure which one to choose.

So far im tempted to implement the token bucket algorithm as described at http://en.wikipedia.org/wiki/Token_bucket . There is Python code associated with this at What's a good rate limiting algorithm? so should be straightforward to implement a Java/Scala version.

Guava has what looks like a nice implementation described at http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/RateLimiter.html

Also Akka seems to implement throttling using the Throttler trait described at : http://doc.akka.io/api/akka/2.1.2/index.html#akka.contrib.throttle.Throttler

I would like to implement my own but don't like re-inventing the wheel if there is a solution already available. Are there advantages to using the token bucket algorithm over using the options already provided by Guava & Scala ?

Out of the three options which is most recommended ?

Mcmillian answered 14/1, 2014 at 15:46 Comment(1)
I think as long as it does what is expected, and doesn't take up a load of resources, any one of those would be viable. I also think the answer greatly depends on the requirements, for instance one approach may be more thread-heavy than another, which would be bad if your implementation was running on infrastructure that charged by CPU-time.Agee

© 2022 - 2024 — McMap. All rights reserved.