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

## Class AIMDBackoffManager

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

- All Implemented Interfaces:
    BackoffManager

      @Experimental
      public class AIMDBackoffManager
      extends Object
      implements BackoffManager

  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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AIMDBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPerRoute)` Creates an `AIMDBackoffManager` to manage per-host connection pool sizes represented by the given `ConnPoolControl`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `backOff(HttpRoute route)` Called when we have decided that the result of using a connection should be interpreted as a backoff signal.
    `void` | `probe(HttpRoute route)` Called when we have determined that the result of using a connection has succeeded and that we may probe for more connections.
    `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.
    `void` | `setCoolDown(org.apache.hc.core5.util.TimeValue coolDown)` Sets the amount of time to wait between adjustments in pool sizes for a given host, to allow enough time for the adjustments to take effect.
    `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).

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

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

- - ### Constructor Detail

    - #### AIMDBackoffManager

          public AIMDBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPerRoute)

      Creates an `AIMDBackoffManager` to manage per-host connection pool sizes represented by the given `ConnPoolControl`.
      Parameters:
        `connPerRoute` - per-host routing maximums to be managed

  - ### Method Detail

    - #### backOff

          public void backOff(HttpRoute route)

      Description copied from interface: `BackoffManager`
      Called when we have decided that the result of using a connection should be interpreted as a backoff signal.
      Specified by:
        `backOff` in interface `BackoffManager`

    - #### probe

          public void probe(HttpRoute route)

      Description copied from interface: `BackoffManager`
      Called when we have determined that the result of using a connection has succeeded and that we may probe for more connections.
      Specified by:
        `probe` in interface `BackoffManager`

    - #### 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.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` - must be between 0.0 and 1.0, exclusive.

    - #### setCoolDown

          public void setCoolDown(org.apache.hc.core5.util.TimeValue coolDown)

      Sets the amount of time to wait between adjustments in pool sizes for a given host, to allow enough time for the adjustments to take effect. Defaults to 5 seconds.
      Parameters:
        `coolDown` - 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

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