Class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

java.lang.Object
com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions.Builder
Enclosing class:
GcpManagedChannelOptions.GcpChannelPoolOptions

public static class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder extends Object
  • Constructor Details

  • Method Details

    • build

    • setMaxSize

      Sets the maximum size of the channel pool.
      Parameters:
      maxSize - maximum number of channels the pool can have.
    • setMinSize

      Sets the minimum size of the channel pool. This number of channels will be created and these channels will try to always keep connection to the server established.
      Parameters:
      minSize - minimum number of channels the pool must have.
    • setInitSize

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setInitSize(int initSize)
      Sets the initial channel pool size. This is the number of channels that the pool will start with. If it is less than setMinSize(int) it is ignored.
      Parameters:
      initSize - number of channels to start the pool with.
      Returns:
    • setDynamicScaling

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval)
      Enables dynamic scaling functionality.

      When the average number of concurrent calls per channel reaches maxRpcPerChannel the pool will create and add a new channel unless already at max size.

      Every scaleDownInterval a check for downscaling is performed. Based on the maximum total concurrent calls observed since the last check, the desired number of channels is calculated as:

      (max_total_concurrent_calls / minRpcPerChannel) rounded up.

      If the calculated desired number of channels is lower than the current number of channels, the pool will be downscaled to the desired number or min size (whichever is greater).

      When downscaling, channels with the oldest connections are selected. Then the selected channels are removed from the pool but are not instructed to shutdown until all calls are completed. In a case when the pool is scaling up and there is a ready channel awaiting calls completion, the channel will be re-used instead of creating a new channel.

      Parameters:
      minRpcPerChannel - minimum desired average concurrent calls per channel.
      maxRpcPerChannel - maximum desired average concurrent calls per channel.
      scaleDownInterval - how often to check for a possibility to scale down.
    • disableDynamicScaling

      Disables dynamic scaling functionality.
      See Also:
    • setConcurrentStreamsLowWatermark

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setConcurrentStreamsLowWatermark(int concurrentStreamsLowWatermark)
      Sets the concurrent streams low watermark. If every channel in the pool has at least this amount of concurrent streams then a new channel will be created in the pool unless the pool reached its maximum size.
      Parameters:
      concurrentStreamsLowWatermark - number of streams every channel must reach before adding a new channel to the pool.
    • setUseRoundRobinOnBind

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setUseRoundRobinOnBind(boolean enabled)
      Enables/disables using round-robin channel selection for affinity binding calls.
      Parameters:
      enabled - If true, use round-robin channel selection for affinity binding calls.
    • setAffinityKeyLifetime

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setAffinityKeyLifetime(Duration affinityKeyLifetime)
      How long to keep an affinity key after its last use. Zero value means keeping keys forever.
      Parameters:
      affinityKeyLifetime - time since last use of a key to include the key in a cleanup.
    • setCleanupInterval

      public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setCleanupInterval(Duration cleanupInterval)
      How frequently affinity key cleanup process should run. Zero value disables cleanup process. If affinityKeyLifetime is not zero, this defaults to affinityKeyLifetime / 10.
      Parameters:
      cleanupInterval - frequency of affinity key cleanup.