Package io.datarouter.ratelimiter
Class DatarouterRateLimiterConfig
java.lang.Object
io.datarouter.ratelimiter.DatarouterRateLimiterConfig
-
Field Details
-
name
-
maxAverageRequests
-
maxSpikeRequests
-
numIntervals
-
bucketTimeInterval
-
bucketIntervalMs
public final int bucketIntervalMs -
unit
-
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
- => 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 ratelimitermaxAverageRequests- threshold average number of requestsmaxSpikeRequests- threshold max number of requestsnumIntervals- number of bucketsbucketTimeInterval- length of each bucketunit- time unit of bucketTimeInterval
-