Classdesc

Cloud Service or Cloud Simulator only.

Default implementation of rate limiter class used by the driver. Two rate limiter instances are used per each table in use, one for reads and another for writes. See RateLimiter.

This implementation uses a token bucket based algorithm, although the state is kept in terms of nano 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 nextNano which is the time when the next operation can proceed without waiting, meaning the limiter is at its limit. All operations issued before nextNano will have to wait accordingly. Based on the value of nextNano and the current time, the appropriate wait time may be computed before the wait begins. If current time is >= nextNano, no wait is needed.

Note that when consumeUnits 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 nextNano as it was to determine its wait time. This should avoid needless wait time when the operations come in rarely.

Because every time when consumeUnits is called with units > 0, nextNano is pushed forward, the operations will be effectively staggered in time accoridng to the order of their arrival with no preferrential treatment given to any operation, thus avoiding starvation.

This 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 maxBurstSecs or 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.

See

Hierarchy

  • SimpleRateLimiter

Implements

Constructors

  • Constructs an instance of SimpleRateLimiter

    Parameters

    • Optional maxBurstSecs: number

      Duration as described above

    Returns SimpleRateLimiter

Methods

  • Implements consumeUnits

    Async

    See

    RateLimiter

    Returns

    Promise resolved with sleeping time in milliseconds or rejected with NoSQLTimeoutError

    Parameters

    • units: number

      Number of units to consume

    • timeout: number

      Timeout in milliseconds

    • consumeOnTimeout: boolean

      Whether to consume units on timeout or throw an error, see consumeUnits

    Returns Promise<number>

  • Implements onThrottle. Called when throttling error occurs when using this rate limiter instance. Current implementation will remove any stored units by ensuring that nextNano is at least the current time.

    Returns void

  • Implements setLimit. Sets the limiter limit (rate) in units per second. Also, enforces minimum duration to be able to store at least one unused unit. When changing table limits, will prorate any unused units according to the new limit.

    Parameters

    • limit: number

      Limit in units

    Returns void

Generated using TypeDoc