class RateLimiter extends AnyRef
Utility class that allows clients to keep track of a rate limit.
The decay rate limiter keeps track of the current rate, allowing temporary bursts. This allows temporary bursts at the risk of overloading the system too quickly.
Clients need to tell an instance whenever they intend to start a new task. The instance will inform the client whether the task can be executed while still meeting the rate limit.
Guarantees:
- Maximum burst size: if
checkAndUpdateRate
is calledn
times in parallel, at mostmax 1, maxTasksPerSecond * maxBurstFactor
calls may returntrue
. - Average rate: if
checkAndUpdateRate
is called at a rate of at leastmaxTasksPerSecond
duringn
seconds, then the number of calls that returntrue
divided byn
is roughlymaxTasksPerSecond
.*
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- RateLimiter
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- Protected
Instance Constructors
- new RateLimiter(maxTasksPerSecond: NonNegativeNumeric[Double], maxBurstFactor: PositiveDouble, nanoTime: => Long = System.nanoTime())
- maxTasksPerSecond
the maximum number of tasks per second
- maxBurstFactor
ratio of max tasks per second when the throtteling should start to kick in
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- final def checkAndUpdateRate(): Boolean
Call this before starting a new task.
Call this before starting a new task.
- returns
whether the tasks can be executed while still meeting the rate limit
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val maxBurst: Double
- val maxTasksPerSecond: NonNegativeNumeric[Double]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])