Package org.apache.hadoop.hbase.quotas
Class RateLimiter
java.lang.Object
org.apache.hadoop.hbase.quotas.RateLimiter
- Direct Known Subclasses:
AverageIntervalRateLimiter
,FixedIntervalRateLimiter
Simple rate limiter. Usage Example: // At this point you have a unlimited resource limiter
RateLimiter limiter = new AverageIntervalRateLimiter(); // or new FixedIntervalRateLimiter();
limiter.set(10, TimeUnit.SECONDS); // set 10 resources/sec while (limiter.getWaitIntervalMs > 0)
{ // wait until waitInterval == 0 Thread.sleep(limiter.getWaitIntervalMs()); } // ...execute the
work and consume the resource... limiter.consume();
-
Field Summary
Modifier and TypeFieldDescriptionprivate long
static final long
private long
static final String
private long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
consume()
consume one available unit.void
consume
(long amount) consume amount available units, amount could be a negative numberlong
long
getLimit()
abstract long
protected long
(package private) abstract long
getWaitInterval
(long limit, long available, long amount) Time in milliseconds to wait for before requesting to consume 'amount' resource.long
Is there at least one resource available to allow execution?long
getWaitIntervalMs
(long amount) Are there enough available resources to allow execution?protected boolean
isAvailable
(long amount) Are there enough available resources to allow execution?boolean
isBypass()
(package private) abstract long
refill
(long limit) Refill the available units w.r.t the elapsed time.void
Set the RateLimiter max available resources and refill period.abstract void
setNextRefillTime
(long nextRefillTime) toString()
void
update
(RateLimiter other) Sets the current instance of RateLimiter to a new values.long
Returns estimate of the ms required to wait before being able to provide 1 resource.long
waitInterval
(long amount) Returns estimate of the ms required to wait before being able to provide "amount" resources.
-
Field Details
-
QUOTA_RATE_LIMITER_CONF_KEY
- See Also:
-
DEFAULT_TIME_UNIT
- See Also:
-
tunit
-
limit
-
avail
-
-
Constructor Details
-
RateLimiter
public RateLimiter()
-
-
Method Details
-
refill
Refill the available units w.r.t the elapsed time.- Parameters:
limit
- Maximum available resource units that can be refilled to.- Returns:
- how many resource units may be refilled ?
-
getWaitInterval
Time in milliseconds to wait for before requesting to consume 'amount' resource.- Parameters:
limit
- Maximum available resource units that can be refilled to.available
- Currently available resource unitsamount
- Resources for which time interval to calculate for- Returns:
- estimate of the ms required to wait before being able to provide 'amount' resources.
-
set
Set the RateLimiter max available resources and refill period.- Parameters:
limit
- The max value available resource units can be refilled to.timeUnit
- Timeunit factor for translating to ms.
-
toString
-
update
Sets the current instance of RateLimiter to a new values. if current limit is smaller than the new limit, bump up the available resources. Otherwise allow clients to use up the previously available resources. -
isBypass
-
getLimit
-
getAvailable
-
getTimeUnitInMillis
-
getWaitIntervalMs
Is there at least one resource available to allow execution?- Returns:
- the waitInterval to backoff, or 0 if execution is allowed
-
getWaitIntervalMs
Are there enough available resources to allow execution?- Parameters:
amount
- the number of required resources, a non-negative number- Returns:
- the waitInterval to backoff, or 0 if execution is allowed
-
isAvailable
Are there enough available resources to allow execution?- Parameters:
amount
- the number of required resources, a non-negative number- Returns:
- true if there are enough available resources, otherwise false
-
consume
consume one available unit. -
consume
consume amount available units, amount could be a negative number- Parameters:
amount
- the number of units to consume
-
waitInterval
Returns estimate of the ms required to wait before being able to provide 1 resource. -
waitInterval
Returns estimate of the ms required to wait before being able to provide "amount" resources. -
setNextRefillTime
-
getNextRefillTime
-