Class DynamicRateExecutor

java.lang.Object
uk.ac.ebi.utils.runcontrol.RateLimitedExecutor
uk.ac.ebi.utils.runcontrol.DynamicRateExecutor
All Implemented Interfaces:
Executor

public abstract class DynamicRateExecutor extends RateLimitedExecutor
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
  • Constructor Details

    • DynamicRateExecutor

      public DynamicRateExecutor()
      Default is to start with no rate limitation, hence Double.MAX_VALUE.
    • DynamicRateExecutor

      public DynamicRateExecutor(double requestsPerSecond)
  • Method Details

    • execute

      public void execute(Runnable action)
      Description copied from class: RateLimitedExecutor
      Controls the execution of the action in such a way that it is run at no more than RateLimitedExecutor.getRate() speed within a given JVM. This is useful when you have a service that is hurt if hammered too fast.
      Specified by:
      execute in interface Executor
      Overrides:
      execute in class RateLimitedExecutor
    • setNewRate

      protected abstract double setNewRate()
      Determines the possible new rate, e.g., based on current performance measurement. Note that this is highest when Double.MAX_VALUE is 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.