RateLimiter

ox.resilience.RateLimiter
See theRateLimiter companion class
object RateLimiter

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def apply(algorithm: RateLimiterAlgorithm)(using Ox): RateLimiter
def fixedWindowWithDuration(maxOperations: Int, window: FiniteDuration)(using Ox): RateLimiter

Creates a rate limiter with a fixed window algorithm.

Creates a rate limiter with a fixed window algorithm.

Takes into account the entire duration of the operation. That is the instant at which the operation "happens" can be anywhere between its start and end. This ensures that the rate limit is always respected, although it might make it more restrictive.

Must be run within an Ox concurrency scope, as a background fork is created, to replenish the rate limiter.

Value parameters

maxOperations

Maximum number of operations that are allowed to run (finishing from previous windows or start new) within a time window.

window

Length of the window.

Attributes

See also
def fixedWindowWithStartTime(maxOperations: Int, window: FiniteDuration)(using Ox): RateLimiter

Creates a rate limiter using a fixed window algorithm. Takes into account the start time of the operation only.

Creates a rate limiter using a fixed window algorithm. Takes into account the start time of the operation only.

Must be run within an Ox concurrency scope, as a background fork is created, to replenish the rate limiter.

Value parameters

maxOperations

Maximum number of operations that are allowed to start within a time window.

window

Interval of time between replenishing the rate limiter. The rate limiter is replenished to allow up to maxOperations in the next time window.

Attributes

See also
def leakyBucket(maxTokens: Int, refillInterval: FiniteDuration)(using Ox): RateLimiter

Creates a rate limiter with token/leaky bucket algorithm. Takes into account the start time of the operation only.

Creates a rate limiter with token/leaky bucket algorithm. Takes into account the start time of the operation only.

Must be run within an Ox concurrency scope, as a background fork is created, to replenish the rate limiter.

Value parameters

maxTokens

Max capacity of tokens in the algorithm, limiting the operations that are allowed to start concurrently.

refillInterval

Interval of time between adding a single token to the bucket.

Attributes

def slidingWindowWithDuration(maxOperations: Int, window: FiniteDuration)(using Ox): RateLimiter

Creates a rate limiter using a sliding window algorithm.

Creates a rate limiter using a sliding window algorithm.

Takes into account the entire duration of the operation. That is the instant at which the operation "happens" can be anywhere between its start and end. This ensures that the rate limit is always respected, although it might make it more restrictive.

Must be run within an Ox concurrency scope, as a background fork is created, to replenish the rate limiter.

Value parameters

maxOperations

Maximum number of operations that are allowed to run (start or finishing) within any window of time.

window

Length of the window.

Attributes

See also
def slidingWindowWithStartTime(maxOperations: Int, window: FiniteDuration)(using Ox): RateLimiter

Creates a rate limiter using a sliding window algorithm. Takes into account the start time of the operation only.

Creates a rate limiter using a sliding window algorithm. Takes into account the start time of the operation only.

Must be run within an Ox concurrency scope, as a background fork is created, to replenish the rate limiter.

Value parameters

maxOperations

Maximum number of operations that are allowed to start within any window of time.

window

Length of the window.

Attributes

See also