Class Backoff

java.lang.Object
org.apache.bookkeeper.common.util.Backoff

public class Backoff extends Object
Implements various backoff strategies.

Strategies are defined by a Stream of durations and are intended to determine the duration after which a task is to be retried.

  • Field Details

  • Constructor Details

    • Backoff

      public Backoff()
  • Method Details

    • constant

      public static Stream<Long> constant(long startMs)
      Create a stream with constant backoffs.
      Parameters:
      startMs - initial backoff in milliseconds
      Returns:
      a stream with constant backoff values.
    • exponential

      public static Stream<Long> exponential(long startMs, int multiplier, long maxMs)
      Create a stream with exponential backoffs.
      Parameters:
      startMs - initial backoff in milliseconds.
      multiplier - the multiplier for next backoff.
      maxMs - max backoff in milliseconds.
      Returns:
      a stream with exponential backoffs.
    • exponentialJittered

      public static Stream<Long> exponentialJittered(long startMs, long maxMs)
      Create a stream of exponential backoffs with jitters.

      This is "full jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

      Parameters:
      startMs - initial backoff in milliseconds.
      maxMs - max backoff in milliseconds.
      Returns:
      a stream of exponential backoffs with jitters.
    • decorrelatedJittered

      public static Stream<Long> decorrelatedJittered(long startMs, long maxMs)
      Create an infinite backoffs that have jitter with a random distribution between startMs and 3 times the previously selected value, capped at maxMs.

      this is "decorrelated jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

      Parameters:
      startMs - initial backoff in milliseconds
      maxMs - max backoff in milliseconds
      Returns:
      a stream of jitter backoffs.
    • equalJittered

      public static Stream<Long> equalJittered(long startMs, long maxMs)
      Create infinite backoffs that keep half of the exponential growth, and jitter between 0 and that amount.

      this is "equal jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

      Parameters:
      startMs - initial backoff in milliseconds.
      maxMs - max backoff in milliseconds.
      Returns:
      a stream of exponential backoffs with jitters.