@InterfaceAudience.Private @InterfaceStability.Evolving public class FixedIntervalRateLimiter extends RateLimiter
Modifier and Type | Field and Description |
---|---|
private long |
nextRefillTime |
static String |
RATE_LIMITER_REFILL_INTERVAL_MS
The FixedIntervalRateLimiter can be harsh from a latency/backoff perspective, which makes it
difficult to fully and consistently utilize a quota allowance.
|
private long |
refillInterval |
DEFAULT_TIME_UNIT, QUOTA_RATE_LIMITER_CONF_KEY
Constructor and Description |
---|
FixedIntervalRateLimiter() |
FixedIntervalRateLimiter(long refillInterval) |
Modifier and Type | Method and Description |
---|---|
long |
getNextRefillTime() |
private long |
getRefillIntervalAdjustedLimit(long limit) |
long |
getWaitInterval(long limit,
long available,
long amount)
Time in milliseconds to wait for before requesting to consume 'amount' resource.
|
long |
refill(long limit)
Refill the available units w.r.t the elapsed time.
|
void |
setNextRefillTime(long nextRefillTime) |
consume, consume, getAvailable, getLimit, getTimeUnitInMillis, getWaitIntervalMs, getWaitIntervalMs, isAvailable, isBypass, set, toString, update, waitInterval, waitInterval
public static final String RATE_LIMITER_REFILL_INTERVAL_MS
RATE_LIMITER_REFILL_INTERVAL_MS
to a lower value you will encourage the rate limiter
to throw smaller wait intervals for requests which may be fulfilled in timeframes shorter than
the quota's full interval. For example, if you're saturating a 100MB/sec read IO quota with a
ton of tiny gets, then configuring this to a value like 100ms will ensure that your retry
backoffs approach ~100ms, rather than 1sec. Be careful not to configure this too low, or you
may produce a dangerous amount of retry volume.private long nextRefillTime
private final long refillInterval
public FixedIntervalRateLimiter()
public FixedIntervalRateLimiter(long refillInterval)
public long refill(long limit)
RateLimiter
refill
in class RateLimiter
limit
- Maximum available resource units that can be refilled to.public long getWaitInterval(long limit, long available, long amount)
RateLimiter
getWaitInterval
in class RateLimiter
limit
- Maximum available resource units that can be refilled to.available
- Currently available resource unitsamount
- Resources for which time interval to calculate forprivate long getRefillIntervalAdjustedLimit(long limit)
public void setNextRefillTime(long nextRefillTime)
setNextRefillTime
in class RateLimiter
public long getNextRefillTime()
getNextRefillTime
in class RateLimiter
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.