Class AveragingProgressTracker

java.lang.Object
org.opendaylight.raft.spi.ProgressTracker
org.opendaylight.raft.spi.AveragingProgressTracker

public final class AveragingProgressTracker extends ProgressTracker
A ProgressTracker subclass which uses ticksWorkedPerClosedTask to compute delays.

This class has tasksOpenLimit used as a (weak) limit, as number of open tasks approaches that value, delays computed are increasing.

In order to keep estimateIsolatedDelay values from raising unreasonably high, defaultTicksPerTask acts as a maximal value. openTask may return higher value if there are tasks above the limit.

On the other hand, there is no delay when number of open tasks is half the limit or less, in order to prevent backend from running out of tasks while there may be waiting frontend threads.

This class is NOT thread-safe.

Author:
Vratko Polak
  • Constructor Details

    • AveragingProgressTracker

      public AveragingProgressTracker(long limit)
      Create a default idle tracker with given limit.
      Parameters:
      limit - of open tasks to avoid exceeding
    • AveragingProgressTracker

      public AveragingProgressTracker(ProgressTracker oldTracker, long limit, long now)
      Construct a new tracker suitable for a new task queue related to a "reconnect".

      The limit is set independently of the old tracker.

      Parameters:
      oldTracker - the tracker used for the previously used backend
      limit - of open tasks to avoid exceeding
      now - tick number corresponding to caller's present
    • AveragingProgressTracker

      public AveragingProgressTracker(AveragingProgressTracker oldTracker, long now)
      Construct a new tracker suitable for a new task queue related to a "reconnect".

      The limit is copied from the old tracker.

      Parameters:
      oldTracker - the tracker used for the previously used backend
      now - tick number corresponding to caller's present
  • Method Details

    • estimateIsolatedDelay

      protected long estimateIsolatedDelay(long now)
      Give an estimate of a fair delay, assuming delays caused by other opened tasks are ignored.

      This implementation returns zero delay if number of open tasks is half of limit or less. Else the delay is computed, aiming to keep number of open tasks at 3/4 of limit, assuming backend throughput remains constant.

      As the number of open tasks approaches the limit, the computed delay increases, but it never exceeds defaultTicksPerTask. That means the actual number of open tasks can exceed the limit.

      Specified by:
      estimateIsolatedDelay in class ProgressTracker
      Parameters:
      now - tick number corresponding to caller's present
      Returns:
      delay (in ticks) after which another openTask() would be fair to be called by the same thread again