Class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder
- Enclosing class:
- GcpManagedChannelOptions.GcpChannelPoolOptions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Disables dynamic scaling functionality.setAffinityKeyLifetime(Duration affinityKeyLifetime) How long to keep an affinity key after its last use.Sets the strategy for picking the least busy channel from the pool.setChannelPrimeMaxAttempts(int channelPrimeMaxAttempts) Sets the maximum number of attempts to prime one scaled-up channel.setChannelPrimer(GcpChannelPrimer channelPrimer) Sets the optional hook that primes newly built scale-up channels concurrently.setChannelPrimeTimeout(Duration channelPrimeTimeout) Sets the maximum time allowed for each channel-primer attempt, including the synchronous call to the primer.setCleanupInterval(Duration cleanupInterval) How frequently affinity key cleanup process should run.setConcurrentStreamsLowWatermark(int concurrentStreamsLowWatermark) Sets the concurrent streams low watermark.setDrainIdleGrace(Duration drainIdleGrace) Sets how long an idle draining channel remains open for sticky affinity references and in-flight calls before its delegate closes.setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval) Enables dynamic scaling functionality.setErrorPenaltyDuration(Duration errorPenaltyDuration) Sets how long an applied penalty takes to decay linearly to zero.setErrorPenaltyStep(int errorPenaltyStep) Sets the load penalty added after each retryable channel error.setInitSize(int initSize) Sets the initial channel pool size.setMaxScaleDownChannels(int channels) setMaxScaleUpPercent(int percent) Sets the maximum percentage of active channels added by one scale-up operation.setMaxSize(int maxSize) Sets the maximum size of the channel pool.setMinSize(int minSize) Sets the minimum size of the channel pool.setScaleDownConsecutiveLowLoadChecks(int checks) setScaleUpCooldown(Duration scaleUpCooldown) Sets the minimum interval between successful scale-up operations.setUseRoundRobinOnBind(boolean enabled) Enables/disables using round-robin channel selection for affinity binding calls.
-
Constructor Details
-
Builder
public Builder() -
Builder
-
-
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
Sets the initial channel pool size. This is the number of channels that the pool will start with. If it is less thansetMinSize(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.After a call is counted, load above
maxRpcPerChannelon its selected channel or across the pool average signals a background scale-up worker.Every
scaleDownInterval, after consecutive low-load checks, the least-loaded channels are marked draining and removed from selection, bounded by maxScaleDownChannels; fewer affinity bindings and then older allocations break load ties. Draining channels receive no new picks or affinity binds and close after their in-flight calls reach zero and drainIdleGrace elapses. Scale-up always creates new channels.- 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:
-
setScaleUpCooldown
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setScaleUpCooldown(Duration scaleUpCooldown) Sets the minimum interval between successful scale-up operations. Zero uses the 10-second default. -
setScaleDownConsecutiveLowLoadChecks
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setScaleDownConsecutiveLowLoadChecks(int checks) -
setMaxScaleUpPercent
Sets the maximum percentage of active channels added by one scale-up operation. The percentage cap has a two-channel floor before desired-size and maximum-size clamps. -
setMaxScaleDownChannels
-
setDrainIdleGrace
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setDrainIdleGrace(Duration drainIdleGrace) Sets how long an idle draining channel remains open for sticky affinity references and in-flight calls before its delegate closes. Defaults to one minute. -
setErrorPenaltyStep
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setErrorPenaltyStep(int errorPenaltyStep) Sets the load penalty added after each retryable channel error. A value of 0 disables error penalties. Each step accumulates on the stored undecayed penalty, capped atmaxRpcPerChannel. Must not be negative. Defaults to 5. -
setErrorPenaltyDuration
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setErrorPenaltyDuration(Duration errorPenaltyDuration) Sets how long an applied penalty takes to decay linearly to zero. Each new retryable error resets the decay timer to a full window. Must be positive. Defaults to 5 seconds. -
setChannelPrimer
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPrimer(@Nullable GcpChannelPrimer channelPrimer) Sets the optional hook that primes newly built scale-up channels concurrently. Only channels added by dynamic scale-up are primed; the initial pool and non-dynamic growth are published as soon as they are built. Each scale-up channel is published individually when its own primer future succeeds. Anullprimer disables priming and preserves the existing scale-up path. -
setChannelPrimeTimeout
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPrimeTimeout(Duration channelPrimeTimeout) Sets the maximum time allowed for each channel-primer attempt, including the synchronous call to the primer. Zero uses the 10-second default. -
setChannelPrimeMaxAttempts
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPrimeMaxAttempts(int channelPrimeMaxAttempts) Sets the maximum number of attempts to prime one scaled-up channel. Zero uses the default of 3. Retry backoff is exponential from 100 ms and capped at 5 s. -
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.
-
setChannelPickStrategy
public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPickStrategy(GcpManagedChannelOptions.ChannelPickStrategy strategy) Sets the strategy for picking the least busy channel from the pool.Defaults to
GcpManagedChannelOptions.ChannelPickStrategy.POWER_OF_TWOwhich avoids the thundering herd problem by sampling two channels with replacement and picking the less busy one. The first sample wins ties, with no channel-warmth preference. Inactive samples are retried.Use
GcpManagedChannelOptions.ChannelPickStrategy.LINEAR_SCANto restore the legacy behavior of scanning all channels and always picking the one with the lowest picker load.- Parameters:
strategy- the channel pick strategy to use.
-