Class DatarouterRateLimiterConfig

java.lang.Object
io.datarouter.ratelimiter.DatarouterRateLimiterConfig

public class DatarouterRateLimiterConfig extends Object
  • Field Details

    • name

      public final String name
    • maxAverageRequests

      public final Long maxAverageRequests
    • maxSpikeRequests

      public final Long maxSpikeRequests
    • numIntervals

      public final Integer numIntervals
    • bucketTimeInterval

      public final Integer bucketTimeInterval
    • bucketIntervalMs

      public final int bucketIntervalMs
    • unit

      public final TimeUnit unit
    • expiration

      public final Duration expiration
  • Constructor Details

    • DatarouterRateLimiterConfig

      public DatarouterRateLimiterConfig(String name, Long maxAverageRequests, Long maxSpikeRequests, Integer numIntervals, Integer bucketTimeInterval, TimeUnit unit)
      Ratelimiters track counts starting the top of the day and time interval. If we have 3 rate limiters with configurations:
      • timeUnit = seconds and bucketInterval = 10
      • timeUnit = hours and bucketInterval = 6
      • timeUnit = minutes and bucketInterval = 4
      And we check for an allow at instant 2009-06-06 11:11:11.123 they will be distributed to the following buckets:
      • => 2009-06-06T11:11:10Z when timeUnit = seconds and bucketInterval = 10
      • => 2009-06-06T06:00:00Z when timeUnit = hours and bucketInterval = 6
      • => 2009-06-06T11:08:00Z when timeUnit = minutes and bucketInterval = 4

      The fist limit that is checked is maxSpikeRequests for the current bucket. The second limit that is check is maxAverageRequests which is the average counts across numIntervals. For the case where numIntervals == 1, the minimum values between maxSpikeRequests and maxAverageRequests will trigger the limit.

      For numIntervals == 1 it is recommended that maxSpikeRequests and maxAverageRequests have the same value.

      Parameters:
      name - name of the ratelimiter
      maxAverageRequests - threshold average number of requests
      maxSpikeRequests - threshold max number of requests
      numIntervals - number of buckets
      bucketTimeInterval - length of each bucket
      unit - time unit of bucketTimeInterval