Package uk.ac.ebi.utils.runcontrol
Class DynamicRateExecutor
java.lang.Object
uk.ac.ebi.utils.runcontrol.RateLimitedExecutor
uk.ac.ebi.utils.runcontrol.DynamicRateExecutor
- All Implemented Interfaces:
Executor
Like
RateLimitedExecutor, but contains a hook where you can dynamically decide which new rate you want to
set. This can be useful to dynamically regulate the throughput of a service, eg, based on its efficiency, measure
via StatsExecutor.- Author:
- brandizi
- Date:
- 19 Oct 2015
-
Field Summary
Fields inherited from class uk.ac.ebi.utils.runcontrol.RateLimitedExecutor
rateLimiter -
Constructor Summary
ConstructorsConstructorDescriptionDefault is to start with no rate limitation, henceDouble.MAX_VALUE.DynamicRateExecutor(double requestsPerSecond) -
Method Summary
Modifier and TypeMethodDescriptionvoidControls the execution of the action in such a way that it is run at no more thanRateLimitedExecutor.getRate()speed within a given JVM.protected abstract doubleDetermines the possible new rate, e.g., based on current performance measurement.Methods inherited from class uk.ac.ebi.utils.runcontrol.RateLimitedExecutor
getRate, setRate
-
Constructor Details
-
DynamicRateExecutor
public DynamicRateExecutor()Default is to start with no rate limitation, henceDouble.MAX_VALUE. -
DynamicRateExecutor
public DynamicRateExecutor(double requestsPerSecond)
-
-
Method Details
-
execute
Description copied from class:RateLimitedExecutorControls the execution of the action in such a way that it is run at no more thanRateLimitedExecutor.getRate()speed within a given JVM. This is useful when you have a service that is hurt if hammered too fast.- Specified by:
executein interfaceExecutor- Overrides:
executein classRateLimitedExecutor
-
setNewRate
protected abstract double setNewRate()Determines the possible new rate, e.g., based on current performance measurement. Note that this is highest whenDouble.MAX_VALUEis set, 0 or negative values are not accepted. Note that the new rate must be different than the old one by more than 0.1%, otherwise no change takes effect.
-