Class 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
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
    • Constructor Detail

      • ExponentialBackoffManager

        public ExponentialBackoffManager​(org.apache.hc.core5.pool.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:
        java.lang.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.
        Specified by:
        setBackoffFactor in class AbstractBackoff
        Parameters:
        rate - the backoff factor to be set