Class ConnectionPoolConfig

java.lang.Object
io.servicetalk.loadbalancer.ConnectionPoolConfig

public abstract class ConnectionPoolConfig extends Object
Configuration of the strategy for selecting connections from a pool to the same endpoint.
  • Method Details

    • corePool

      public static ConnectionPoolConfig corePool(int corePoolSize, boolean forceCorePool)
      A connection selection strategy that prioritizes a configurable "core" pool.

      This ConnectionPoolStrategy attempts to emulate the pooling behavior often seen in thread pools. Specifically it allows for the configuration of a "core pool" size which are intended to be long-lived. Iteration starts in the core pool at a random position and then iterates through the entire core pool before moving to an overflow pool. Because iteration of this core pool starts at a random position the core connections will get an even traffic load and, because they are equally selectable, will tend not to be removed due to idleness.

      If the core pool cannot satisfy the load traffic can spill over to extra connections which are selected in-order. This has the property of minimizing traffic to the latest elements added outside the core pool size, thus let them idle out of the pool once they're no longer necessary.

      Parameters:
      corePoolSize - the size of the core pool.
      forceCorePool - whether to avoid selecting connections from the core pool until it has reached the configured core pool size.
      Returns:
      the configured ConnectionPoolConfig.
    • linearSearch

      public static ConnectionPoolConfig linearSearch()
      A connection selection strategy that prioritizes connection reuse.

      This ConnectionPoolStrategy attempts to minimize the number of connections by attempting to direct traffic to connections in the order they were created in linear order up until a configured quantity. After this linear pool is exhausted the remaining connections will be selected from at random. Prioritizing traffic to the existing connections will let tailing connections be removed due to idleness.

      Returns:
      the configured ConnectionPoolConfig.
    • linearSearch

      public static ConnectionPoolConfig linearSearch(int linearSearchSpace)
      A connection selection strategy that prioritizes connection reuse.

      This ConnectionPoolStrategy attempts to minimize the number of connections by attempting to direct traffic to connections in the order they were created in linear order up until a configured quantity. After this linear pool is exhausted the remaining connections will be selected from at random. Prioritizing traffic to the existing connections will let tailing connections be removed due to idleness.

      Parameters:
      linearSearchSpace - the space to search linearly before resorting to random selection for remaining connections.
      Returns:
      the configured ConnectionPoolConfig.
    • p2c

      public static ConnectionPoolConfig p2c(int corePoolSize, boolean forceCorePool)
      A ConnectionPoolStrategy that attempts to discern between the health of individual connections. If individual connections have health data the P2C strategy can be used to bias traffic toward the best connections. This has the following algorithm: - Randomly select two connections from the 'core pool' (pick-two). - Try to select the 'best' of the two connections. - If we fail to select the best connection, try the other connection. - If both connections fail, repeat the pick-two operation for up to maxEffort attempts, begin linear iteration through the remaining connections searching for an acceptable connection.
      Parameters:
      corePoolSize - the size of the core pool.
      forceCorePool - whether to avoid selecting connections from the core pool until it has reached the configured core pool size.
      Returns:
      the configured ConnectionPoolConfig.
    • p2c

      public static ConnectionPoolConfig p2c(int maxEffort, int corePoolSize, boolean forceCorePool)
      A ConnectionPoolStrategy that attempts to discern between the health of individual connections. If individual connections have health data the P2C strategy can be used to bias traffic toward the best connections. This has the following algorithm: - Randomly select two connections from the 'core pool' (pick-two). - Try to select the 'best' of the two connections. - If we fail to select the best connection, try the other connection. - If both connections fail, repeat the pick-two operation for up to maxEffort attempts, begin linear iteration through the remaining connections searching for an acceptable connection.
      Parameters:
      maxEffort - the maximum number of attempts to pick a healthy connection from the core pool.
      corePoolSize - the size of the core pool.
      forceCorePool - whether to avoid selecting connections from the core pool until it has reached the configured core pool size.
      Returns:
      the configured ConnectionPoolConfig.