Package org.apache.hadoop.hbase.quotas
Class RateLimiter
java.lang.Object
org.apache.hadoop.hbase.quotas.RateLimiter
- Direct Known Subclasses:
AverageIntervalRateLimiter,FeedbackAdaptiveRateLimiter,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
FieldsModifier and TypeFieldDescriptionprivate longstatic final longprivate longstatic final Stringprivate long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconsume()consume one available unit.voidconsume(long amount) consume amount available units, amount could be a negative numberlonglonggetLimit()abstract longprotected long(package private) abstract longgetWaitInterval(long limit, long available, long amount) Time in milliseconds to wait for before requesting to consume 'amount' resource.longIs there at least one resource available to allow execution?longgetWaitIntervalMs(long amount) Are there enough available resources to allow execution?protected booleanisAvailable(long amount) Are there enough available resources to allow execution?booleanisBypass()(package private) abstract longrefill(long limit) Refill the available units w.r.t the elapsed time.voidSet the RateLimiter max available resources and refill period.abstract voidsetNextRefillTime(long nextRefillTime) toString()voidupdate(RateLimiter other) Sets the current instance of RateLimiter to a new values.longReturns estimate of the ms required to wait before being able to provide 1 resource.longwaitInterval(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
-