Top Description Fields Constructors Methods
org.apache.hc.client5.http.impl.classic

public Class ExponentialBackoffManager

extends AbstractBackoff
Class Inheritance
Imports
org.apache.hc.client5.http.HttpRoute, org.apache.hc.core5.pool.ConnPoolControl, org.apache.hc.core5.util.Args, org.slf4j.Logger, .LoggerFactory

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 Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
public
ExponentialBackoffManager(final ConnPoolControl<HttpRoute>
the connection pool control to be used for managing connections
connPerRoute
)

Constructs a new ExponentialBackoffManager with the specified connection pool control.

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

the new pool size after applying the backoff
getBackedOffPoolSize
(final int
the current pool size
curr
)

Implements abstract org.apache.hc.client5.http.impl.classic.AbstractBackoff.getBackedOffPoolSize.

Calculates the new pool size after applying the exponential backoff algorithm.
public void
setBackoffFactor(final double
the backoff factor to be set
rate
)

Implements abstract org.apache.hc.client5.http.impl.classic.AbstractBackoff.setBackoffFactor.

Sets the backoff factor for the backoff algorithm.
Inherited from org.apache.hc.client5.http.impl.classic.AbstractBackoff:
backOffgetBackoffFactorgetCapgetConnPerRoutegetCoolDowngetLastRouteBackoffsgetLastRouteProbesgetLastUpdategetTimeIntervalprobesetCoolDownsetPerHostConnectionCap

Field Detail

LOGback to summary
private static final Logger LOG

Hides org.apache.hc.client5.http.impl.classic.AbstractBackoff.LOG.

Constructor Detail

ExponentialBackoffManagerback to summary
public ExponentialBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute)

Constructs a new ExponentialBackoffManager with the specified connection pool control.

Parameters
connPerRoute:ConnPoolControl<HttpRoute>

the connection pool control to be used for managing connections

Exceptions
IllegalArgumentException:
if connPerRoute is null

Method Detail

getBackedOffPoolSizeback to summary
protected int getBackedOffPoolSize(final int curr)

Implements abstract org.apache.hc.client5.http.impl.classic.AbstractBackoff.getBackedOffPoolSize.

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.

Parameters
curr:int

the current pool size

Returns:int

the new pool size after applying the backoff

setBackoffFactorback to summary
public void setBackoffFactor(final double rate)

Implements abstract org.apache.hc.client5.http.impl.classic.AbstractBackoff.setBackoffFactor.

Doc from org.apache.hc.client5.http.impl.classic.AbstractBackoff.setBackoffFactor.

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:double

the backoff factor to be set