Package com.linkedin.venice.throttle
Class EventThrottler
java.lang.Object
com.linkedin.venice.throttle.EventThrottler
- All Implemented Interfaces:
VeniceRateLimiter
- Direct Known Subclasses:
VeniceAdaptiveIngestionThrottler
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 to
maybeThrottle(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
Modifier and TypeFieldDescriptionstatic final EventThrottlingStrategy
static final EventThrottlingStrategy
-
Constructor Summary
ConstructorDescriptionEventThrottler
(long maxRatePerSecond) EventThrottler
(long maxRatePerSecond, long intervalMs, String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy) EventThrottler
(long maxRatePerSecond, String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy) EventThrottler
(io.tehuti.utils.Time time, long maxRatePerSecond, long intervalMs, String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy) EventThrottler
(io.tehuti.utils.Time time, LongSupplier maxRatePerSecondProvider, long intervalMs, String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy) EventThrottler
(LongSupplier maxRatePerSecondProvider, long intervalMs, String throttlerName, boolean checkQuotaBeforeRecording, EventThrottlingStrategy throttlingStrategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected long
final long
long
getQuota()
protected io.tehuti.metrics.MetricConfig
protected io.tehuti.utils.Time
getTime()
protected boolean
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.toString()
boolean
tryAcquirePermit
(int units) Try to acquire permit for the given rcu.
-
Field Details
-
BLOCK_STRATEGY
-
REJECT_STRATEGY
-
-
Constructor Details
-
EventThrottler
public EventThrottler() -
EventThrottler
public EventThrottler(long maxRatePerSecond) - Parameters:
maxRatePerSecond
- Maximum rate that this throttler should allow (-1 is unlimited)
-
EventThrottler
public EventThrottler(long maxRatePerSecond, 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, 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, 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(LongSupplier maxRatePerSecondProvider, long intervalMs, 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, LongSupplier maxRatePerSecondProvider, long intervalMs, 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 Details
-
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
-