Package com.linkedin.venice.throttle
Class EventThrottler
- java.lang.Object
-
- com.linkedin.venice.throttle.EventThrottler
-
- All Implemented Interfaces:
VeniceRateLimiter
public class EventThrottler extends java.lang.Object implements VeniceRateLimiter
A class to throttle Events to a certain rate This class takes a maximum rate in events/sec and a minimum interval over which to check the rate. The rate is measured over two rolling windows: one full window, and one in-flight window. Each window is bounded to the provided interval in ms, therefore, the total interval measured over is up to twice the provided interval parameter. If the current event rate exceeds the maximum, the call tomaybeThrottle(double)
will handle this case based on the given throttling strategy. This is a generalized IoThrottler as it existed before, which can be used to throttle Bytes read or written, number of entries scanned, etc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.linkedin.venice.throttle.VeniceRateLimiter
VeniceRateLimiter.RateLimiterType
-
-
Field Summary
Fields Modifier and Type Field Description static EventThrottlingStrategy
BLOCK_STRATEGY
static EventThrottlingStrategy
REJECT_STRATEGY
-
Constructor Summary
Constructors Constructor Description EventThrottler(long maxRatePerSecond)
EventThrottler(long maxRatePerSecond, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
EventThrottler(long maxRatePerSecond, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
EventThrottler(io.tehuti.utils.Time time, long maxRatePerSecond, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
EventThrottler(io.tehuti.utils.Time time, java.util.function.LongSupplier maxRatePerSecondProvider, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
EventThrottler(java.util.function.LongSupplier maxRatePerSecondProvider, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected long
getConfiguredMaxRatePerSecond()
long
getMaxRatePerSecond()
long
getQuota()
protected io.tehuti.metrics.MetricConfig
getRateConfig()
protected io.tehuti.utils.Time
getTime()
protected boolean
isCheckQuotaBeforeRecording()
void
maybeThrottle(double eventsSeen)
Sleeps if necessary to slow down the caller.void
setQuota(long quota)
The following methods are used only when checking if the new quota requests are different from the existing quota.java.lang.String
toString()
boolean
tryAcquirePermit(int units)
Try to acquire permit for the given rcu.
-
-
-
Field Detail
-
BLOCK_STRATEGY
public static final EventThrottlingStrategy BLOCK_STRATEGY
-
REJECT_STRATEGY
public static final EventThrottlingStrategy REJECT_STRATEGY
-
-
Constructor Detail
-
EventThrottler
public EventThrottler(long maxRatePerSecond)
- Parameters:
maxRatePerSecond
- Maximum rate that this throttler should allow (-1 is unlimited)
-
EventThrottler
public EventThrottler(long maxRatePerSecond, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
- Parameters:
maxRatePerSecond
- Maximum rate that this throttler should allow (-1 is unlimited)throttlerName
- if specified, the throttler will share its limit with others named the same if null, the throttler will be independent of the othersthrottlingStrategy
- the strategy how throttler handle the quota exceeding case.checkQuotaBeforeRecording
- if true throttler will check the quota before recording usage, otherwise throttler will record usage then check the quota.
-
EventThrottler
public EventThrottler(long maxRatePerSecond, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
- Parameters:
maxRatePerSecond
- Maximum rate that this throttler should allow (-1 is unlimited)intervalMs
- Minimum interval over which the rate is measured (maximum is twice that)throttlerName
- if specified, the throttler will share its limit with others named the same if null, the throttler will be independent of the otherscheckQuotaBeforeRecording
- if true throttler will check the quota before recording usage, otherwise throttler will record usage then check the quota.throttlingStrategy
- the strategy how throttler handle the quota exceeding case.
-
EventThrottler
public EventThrottler(io.tehuti.utils.Time time, long maxRatePerSecond, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
- Parameters:
time
- Used to inject aTime
in testsmaxRatePerSecond
- Maximum rate that this throttler should allow (-1 is unlimited)intervalMs
- Minimum interval over which the rate is measured (maximum is twice that)throttlerName
- if specified, the throttler will share its limit with others named the same if null, the throttler will be independent of the otherscheckQuotaBeforeRecording
- if true throttler will check the quota before recording usage, otherwise throttler will record usage then check the quota.throttlingStrategy
- the strategy how throttler handle the quota exceeding case.
-
EventThrottler
public EventThrottler(java.util.function.LongSupplier maxRatePerSecondProvider, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy)
- Parameters:
maxRatePerSecondProvider
- Provider for maximum rate that this throttler should allow (-1 is unlimited)intervalMs
- Minimum interval over which the rate is measured (maximum is twice that)throttlerName
- if specified, the throttler will share its limit with others named the same if null, the throttler will be independent of the otherscheckQuotaBeforeRecording
- if true throttler will check the quota before recording usage, otherwise throttler will record usage then check the quota.throttlingStrategy
- the strategy how throttler handle the quota exceeding case.
-
EventThrottler
public EventThrottler(@Nonnull io.tehuti.utils.Time time, java.util.function.LongSupplier maxRatePerSecondProvider, long intervalMs, java.lang.String throttlerName, boolean checkQuotaBeforeRecording, @Nonnull EventThrottlingStrategy throttlingStrategy)
- Parameters:
time
- Used to inject aTime
in testsmaxRatePerSecondProvider
- Provider for maximum rate that this throttler should allow (-1 is unlimited)intervalMs
- Minimum interval over which the rate is measured (maximum is twice that)throttlerName
- if specified, the throttler will share its limit with others named the same if null, the throttler will be independent of the otherscheckQuotaBeforeRecording
- if true throttler will check the quota before recording usage, otherwise throttler will record usage then check the quota.throttlingStrategy
- the strategy how throttler handle the quota exceeding case.
-
-
Method Detail
-
maybeThrottle
public void maybeThrottle(double eventsSeen)
Sleeps if necessary to slow down the caller.- Parameters:
eventsSeen
- Number of events seen since last invocation. Basis for determining whether its necessary to sleep.
-
getMaxRatePerSecond
public final long getMaxRatePerSecond()
-
getTime
protected io.tehuti.utils.Time getTime()
-
getRateConfig
protected io.tehuti.metrics.MetricConfig getRateConfig()
-
getConfiguredMaxRatePerSecond
protected long getConfiguredMaxRatePerSecond()
-
isCheckQuotaBeforeRecording
protected boolean isCheckQuotaBeforeRecording()
-
tryAcquirePermit
public boolean tryAcquirePermit(int units)
Description copied from interface:VeniceRateLimiter
Try to acquire permit for the given rcu. Will not block if permit is not available.- Specified by:
tryAcquirePermit
in interfaceVeniceRateLimiter
- Parameters:
units
- Number of units to acquire.- Returns:
- true if permit is acquired, false otherwise.
-
setQuota
public void setQuota(long quota)
Description copied from interface:VeniceRateLimiter
The following methods are used only when checking if the new quota requests are different from the existing quota.- Specified by:
setQuota
in interfaceVeniceRateLimiter
-
getQuota
public long getQuota()
- Specified by:
getQuota
in interfaceVeniceRateLimiter
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-