Class AIMDBackoffManager
- java.lang.Object
-
- org.apache.http.impl.client.AIMDBackoffManager
-
- All Implemented Interfaces:
BackoffManager
public class AIMDBackoffManager extends java.lang.Object implements BackoffManager
The
AIMDBackoffManagerapplies 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
Fields Modifier and Type Field Description private doublebackoffFactorprivate intcapprivate Clockclockprivate org.apache.http.pool.ConnPoolControl<HttpRoute>connPerRouteprivate longcoolDownprivate java.util.Map<HttpRoute,java.lang.Long>lastRouteBackoffsprivate java.util.Map<HttpRoute,java.lang.Long>lastRouteProbes
-
Constructor Summary
Constructors Constructor Description AIMDBackoffManager(org.apache.http.pool.ConnPoolControl<HttpRoute> connPerRoute)Creates anAIMDBackoffManagerto manage per-host connection pool sizes represented by the givenConnPoolControl.AIMDBackoffManager(org.apache.http.pool.ConnPoolControl<HttpRoute> connPerRoute, Clock clock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackOff(HttpRoute route)Called when we have decided that the result of using a connection should be interpreted as a backoff signal.private intgetBackedOffPoolSize(int curr)private java.lang.LonggetLastUpdate(java.util.Map<HttpRoute,java.lang.Long> updates, HttpRoute route)voidprobe(HttpRoute route)Called when we have determined that the result of using a connection has succeeded and that we may probe for more connections.voidsetBackoffFactor(double d)Sets the factor to use when backing off; the new per-host limit will be roughly the current max times this factor.voidsetCooldownMillis(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.voidsetPerHostConnectionCap(int cap)Sets the absolute maximum per-host connection pool size to probe up to; defaults to 2 (the default per-host max).
-
-
-
Field Detail
-
connPerRoute
private final org.apache.http.pool.ConnPoolControl<HttpRoute> connPerRoute
-
clock
private final Clock clock
-
lastRouteProbes
private final java.util.Map<HttpRoute,java.lang.Long> lastRouteProbes
-
lastRouteBackoffs
private final java.util.Map<HttpRoute,java.lang.Long> lastRouteBackoffs
-
coolDown
private long coolDown
-
backoffFactor
private double backoffFactor
-
cap
private int cap
-
-
Constructor Detail
-
AIMDBackoffManager
public AIMDBackoffManager(org.apache.http.pool.ConnPoolControl<HttpRoute> connPerRoute)
Creates anAIMDBackoffManagerto manage per-host connection pool sizes represented by the givenConnPoolControl.- Parameters:
connPerRoute- per-host routing maximums to be managed
-
-
Method Detail
-
backOff
public void backOff(HttpRoute route)
Description copied from interface:BackoffManagerCalled when we have decided that the result of using a connection should be interpreted as a backoff signal.- Specified by:
backOffin interfaceBackoffManager
-
getBackedOffPoolSize
private int getBackedOffPoolSize(int curr)
-
probe
public void probe(HttpRoute route)
Description copied from interface:BackoffManagerCalled when we have determined that the result of using a connection has succeeded and that we may probe for more connections.- Specified by:
probein interfaceBackoffManager
-
getLastUpdate
private java.lang.Long getLastUpdate(java.util.Map<HttpRoute,java.lang.Long> updates, HttpRoute route)
-
setBackoffFactor
public void setBackoffFactor(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.flooris 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- must be between 0.0 and 1.0, exclusive.
-
setCooldownMillis
public void setCooldownMillis(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- must be positive
-
setPerHostConnectionCap
public void setPerHostConnectionCap(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- must be >= 1
-
-