org.apache.hc.client5.http.impl.classic

## Class ExponentialBackoffManager

- java.lang.Object
- - org.apache.hc.client5.http.impl.classic.AbstractBackoff
  - - org.apache.hc.client5.http.impl.classic.ExponentialBackoffManager

- All Implemented Interfaces:
    BackoffManager

      public class ExponentialBackoffManager
      extends AbstractBackoff

  A backoff manager implementation that uses an exponential backoff algorithm to adjust the maximum number of connections per HTTP route. The algorithm reduces the number of connections in response to adverse events, such as connection failures, and gradually increases the number of connections when the route is operating without issues.

  This implementation is specifically designed for managing connections in an HTTP route context and provides methods for probing and backing off connections based on the performance of the route.

  The exponential backoff algorithm is primarily implemented in the `getBackedOffPoolSize` method, which calculates the new connection pool size based on the current pool size, growth rate, and the number of time intervals.

  Since:
    5.3

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExponentialBackoffManager(ConnPoolControl<HttpRoute> connPerRoute)` Constructs a new ExponentialBackoffManager with the specified connection pool control.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `getBackedOffPoolSize(int curr)` Calculates the new pool size after applying the exponential backoff algorithm.
    `void` | `setBackoffFactor(double rate)` Sets the backoff factor for the backoff algorithm.

    - ### Methods inherited from class org.apache.hc.client5.http.impl.classic.AbstractBackoff

      `backOff, getBackoffFactor, getCap, getConnPerRoute, getCoolDown, getLastRouteBackoffs, getLastRouteProbes, getLastUpdate, getTimeInterval, probe, setCoolDown, setPerHostConnectionCap`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExponentialBackoffManager

          public ExponentialBackoffManager(ConnPoolControl<HttpRoute> connPerRoute)

      Constructs a new ExponentialBackoffManager with the specified connection pool control.
      Parameters:
        `connPerRoute` - the connection pool control to be used for managing connections
      Throws:
        `IllegalArgumentException` - if connPerRoute is null

  - ### Method Detail

    - #### getBackedOffPoolSize

          protected int getBackedOffPoolSize(int curr)

      Calculates the new pool size after applying the exponential backoff algorithm. The new pool size is calculated using the formula: floor(curr / (1 + growthRate) ^ t), where curr is the current pool size, growthRate is the exponential growth rate, and t is the time interval.
      Specified by:
        `getBackedOffPoolSize` in class `AbstractBackoff`
      Parameters:
        `curr` - the current pool size
      Returns:
        the new pool size after applying the backoff

    - #### setBackoffFactor

          public void setBackoffFactor(double rate)

      Description copied from class: `AbstractBackoff`
      Sets the backoff factor for the backoff algorithm. The backoff factor should be a value between 0.0 and 1.0. The specific implementation of how the backoff factor is used should be provided by subclasses.
      Parameters:
        `rate` - the backoff factor to be set

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.