Top Description Fields Constructors Methods
org.apache.http.impl.client

public Class AIMDBackoffManager

extends Object
implements BackoffManager
Class Inheritance
All Implemented Interfaces
org.apache.http.client.BackoffManager
Imports
java.util.HashMap, .Map, org.apache.http.client.BackoffManager, org.apache.http.conn.routing.HttpRoute, org.apache.http.pool.ConnPoolControl, org.apache.http.util.Args

The AIMDBackoffManager applies an additive increase, multiplicative decrease (AIMD) to managing a dynamic limit to the number of connections allowed to a given host. You may want to experiment with the settings for the cooldown periods and the backoff factor to get the adaptive behavior you want.

Generally speaking, shorter cooldowns will lead to more steady-state variability but faster reaction times, while longer cooldowns will lead to more stable equilibrium behavior but slower reaction times.

Similarly, higher backoff factors promote greater utilization of available capacity at the expense of fairness among clients. Lower backoff factors allow equal distribution of capacity among clients (fairness) to happen faster, at the expense of having more server capacity unused in the short term.

Since
4.2

Field Summary

Modifier and TypeField and Description
private double
private int
private final Clock
private final ConnPoolControl<HttpRoute>
private long
private final Map<HttpRoute, Long>
private final Map<HttpRoute, Long>

Constructor Summary

AccessConstructor and Description
public
AIMDBackoffManager(final ConnPoolControl<HttpRoute>
per-host routing maximums to be managed
connPerRoute
)

Creates an AIMDBackoffManager to manage per-host connection pool sizes represented by the given ConnPoolControl.

pack-priv
AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute, final Clock clock)

Method Summary

Modifier and TypeMethod and Description
public void
backOff(final HttpRoute route)

Implements org.apache.http.client.BackoffManager.backOff.

Called when we have decided that the result of using a connection should be interpreted as a backoff signal.
private int
getBackedOffPoolSize(final int curr)

private Long
getLastUpdate(final Map<HttpRoute, Long> updates, final HttpRoute route)

public void
probe(final HttpRoute route)

Implements org.apache.http.client.BackoffManager.probe.

Called when we have determined that the result of using a connection has succeeded and that we may probe for more connections.
public void
setBackoffFactor(final double
must be between 0.0 and 1.0, exclusive.
d
)

Sets the factor to use when backing off; the new per-host limit will be roughly the current max times this factor.

public void
setCooldownMillis(final long
must be positive
l
)

Sets the amount of time, in milliseconds, to wait between adjustments in pool sizes for a given host, to allow enough time for the adjustments to take effect.

public void
setPerHostConnectionCap(final int
must be >= 1
cap
)

Sets the absolute maximum per-host connection pool size to probe up to; defaults to 2 (the default per-host max).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backoffFactorback to summary
private double backoffFactor
capback to summary
private int cap
clockback to summary
private final Clock clock
connPerRouteback to summary
private final ConnPoolControl<HttpRoute> connPerRoute
coolDownback to summary
private long coolDown
lastRouteBackoffsback to summary
private final Map<HttpRoute, Long> lastRouteBackoffs
lastRouteProbesback to summary
private final Map<HttpRoute, Long> lastRouteProbes

Constructor Detail

AIMDBackoffManagerback to summary
public AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute)

Creates an AIMDBackoffManager to manage per-host connection pool sizes represented by the given ConnPoolControl.

Parameters
connPerRoute:ConnPoolControl<HttpRoute>

per-host routing maximums to be managed

AIMDBackoffManagerback to summary
pack-priv AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute, final Clock clock)

Method Detail

backOffback to summary
public void backOff(final HttpRoute route)

Implements org.apache.http.client.BackoffManager.backOff.

Doc from org.apache.http.client.BackoffManager.backOff.

Called when we have decided that the result of using a connection should be interpreted as a backoff signal.

Annotations
@Override
getBackedOffPoolSizeback to summary
private int getBackedOffPoolSize(final int curr)
getLastUpdateback to summary
private Long getLastUpdate(final Map<HttpRoute, Long> updates, final HttpRoute route)
probeback to summary
public void probe(final HttpRoute route)

Implements org.apache.http.client.BackoffManager.probe.

Doc from org.apache.http.client.BackoffManager.probe.

Called when we have determined that the result of using a connection has succeeded and that we may probe for more connections.

Annotations
@Override
setBackoffFactorback to summary
public void setBackoffFactor(final double d)

Sets the factor to use when backing off; the new per-host limit will be roughly the current max times this factor. Math.floor is applied in the case of non-integer outcomes to ensure we actually decrease the pool size. Pool sizes are never decreased below 1, however. Defaults to 0.5.

Parameters
d:double

must be between 0.0 and 1.0, exclusive.

setCooldownMillisback to summary
public void setCooldownMillis(final long l)

Sets the amount of time, in milliseconds, to wait between adjustments in pool sizes for a given host, to allow enough time for the adjustments to take effect. Defaults to 5000L (5 seconds).

Parameters
l:long

must be positive

setPerHostConnectionCapback to summary
public void setPerHostConnectionCap(final int cap)

Sets the absolute maximum per-host connection pool size to probe up to; defaults to 2 (the default per-host max).

Parameters
cap:int

must be >= 1