public class RateLimiterLoadController extends LoadController implements ILoadController
It works as follows: whenever you want to accept a new incoming message in the system, you call the allow() method. If it returns true, process the message, if it returns false, dont, i.e. either drop the message or delay its injection into the application. When a processed message is acknowledged,fully processed by the application, call the update method with the corresponding processing time in millisecond.
The load controller keeps track of an average traversal time, and will start telling you to slow down if it detects an increase in the response time. However, when doing that it will keep let some messages pass so that the traversal time can still be computed, and so as not to brutally stop traffic processing.
The load controller can be in one of two state: BLOCKED: only a fraction of the traffic is accepted. NORMAL: all the traffic is accepted.
Every time it enters the BLOCKED state, the load controller computes an estimated message rate, used to compute what fraction of the traffic should be allowed to pass. The higher the increase in RTT, the smaller that fraction.
You can question the statistics of the load controller, in particular the ration of allowed message, from the beginning or in the last 10 seconds interval.
The main parameter influencing the behavior of that load comntroller is the alpha parameter used in computing the average RTT. The formula is a standard weighted moving average:
newRtt = alpha * value + + (1-alpha) * currentRTT
The smaller alpha, the less weight the latest value. In practice a 0.05 value is good enough so as to react quickly enough. If you use 0.01 or smaller, the controlled will be more defensive, and will end up refusing more traffic than it should.
lastStatTimestamp, statsDelay| Constructor and Description |
|---|
RateLimiterLoadController(org.thales.punch.libraries.metrics.api.IMetricContext metricsContext)
Create a new load controller with the default starting response time (RTT) of 30000, i.e.
|
| Modifier and Type | Method and Description |
|---|---|
void |
ack(long v)
update the controller statistics.
|
LoadController |
configure(org.thales.punch.settings.api.ISettingsMap settings)
Configure a load controller.
|
protected void |
debug()
dump some useful infos.
|
void |
fail(long v)
update the controller statistics.
|
int |
getCurrentRate() |
void |
regulate()
regulate the traffic, this method potentially take some time before returning.
|
RateLimiterLoadController |
setAdaptative(Boolean asBoolean)
activate an adaptative load control.
|
RateLimiterLoadController |
setRate(long rate)
Set the rate expressed in eps
|
RateLimiterLoadController |
setStatsDelay(long delay)
set the stats publishing delay
|
factory, setMaxTimeoutSecclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetMaxTimeoutSecpublic RateLimiterLoadController(org.thales.punch.libraries.metrics.api.IMetricContext metricsContext)
metricsContext - the provider of metrics registry and context tagspublic RateLimiterLoadController setStatsDelay(long delay)
delay - the delay in millisecondspublic RateLimiterLoadController setRate(long rate)
rate - the rate in event per secondpublic void ack(long v)
ILoadControllerack in interface ILoadControllerack in class LoadControllerv - the traversal time of a tuple, in millisecondspublic void fail(long v)
ILoadControllerfail in interface ILoadControllerfail in class LoadControllerv - the traversal time of a tuple, in millisecondspublic void regulate()
ILoadControllerregulate in interface ILoadControllerregulate in class LoadControllerprotected void debug()
debug in class LoadControllerpublic LoadController configure(org.thales.punch.settings.api.ISettingsMap settings)
LoadControllerconfigure in class LoadControllersettings - the caller load contraoller settingspublic RateLimiterLoadController setAdaptative(Boolean asBoolean)
asBoolean - true to activate the adaptative behaviorpublic int getCurrentRate()
getCurrentRate in interface ILoadControllergetCurrentRate in class LoadControllerCopyright © 2023. All rights reserved.