Class NoSQLRateLimiter
Implements
Namespace: Oracle.NoSQL.SDK
Assembly: Oracle.NoSQL.SDK.dll
Syntax
public class NoSQLRateLimiter : Object, IRateLimiter
Remarks
This class implements default rate limiting algorithm used by the SDK. The driver will use it if rate limiting is enabled and you did not specify RateLimiterCreator delegate. You do not need to create or use instances of this class, the following is presented for information only.
Two rate limiter instances are used per each table in use, one for reads and another for writes (see IRateLimiter).
This implementation uses a token bucket based algorithm, although the
state is kept in terms of time instead of tokens. It is assumed
that the units refill at constant rate being equivalent to the set
limit of units per second. The state is kept in terms of
next
, which is the time when the next operation can proceed
without waiting, meaning the limiter is at its limit. All operations
issued before next
will have to wait accordingly. Based on
the value of next
and the current time, the appropriate
wait time may be computed before the wait begins. If current time is
greater than or equal to next
, no wait is needed.
Note that when ConsumeUnitsAsync(Int32, TimeSpan, Boolean, CancellationToken) is called, the entered
units will only affect the wait time of subsequent operations and not
the current operation, which will use the value of next
as
it currently is to determine the wait time. This is done to avoid
needless wait time when the operations come in rarely.
Because every time when ConsumeUnitsAsync(Int32, TimeSpan, Boolean, CancellationToken) is called with
positive number of units, next
is pushed forward, the
operations will be effectively staggered in time according to the
order of their arrival with no preferential treatment given to any
operation, thus avoiding starvation.
This rate limiter uses burst mode, allowing a set maximum number of stored units that has not been used to be consumed immediately without waiting. This value is expressed as duration, which is effectively a maximum number of seconds worth of unused stored units. The minimum duration is internally bound such that at least one unused unit may be consumed without waiting. The default value of duration is 30 seconds.
Constructors
Name | Description |
---|---|
NoSQLRateLimiter() | Initializes new instance of NoSQLRateLimiter with a default duration of 30 seconds. |
NoSQLRateLimiter(TimeSpan) | Initializes new instance of NoSQLRateLimiter with given a given duration. |
Methods
Name | Description |
---|---|
ConsumeUnitsAsync(Int32, TimeSpan, Boolean, CancellationToken) | Consumes the specified number of units and blocks (sleeps) asynchronously if required before an operation can proceed. |
HandleThrottlingException(RetryableException) | Defines the behavior of the rate limiter when throttling exception occurs. |
SetLimit(Double) | Configures rate limiter by setting its limit in units per second. |