Class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder (1.17.0)

public static class GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

Inheritance

java.lang.Object > GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

Constructors

Builder()

public Builder()

Builder(GcpManagedChannelOptions.GcpChannelPoolOptions options)

public Builder(GcpManagedChannelOptions.GcpChannelPoolOptions options)
Parameter
Name Description
options GcpManagedChannelOptions.GcpChannelPoolOptions

Methods

build()

public GcpManagedChannelOptions.GcpChannelPoolOptions build()
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions

disableDynamicScaling()

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder disableDynamicScaling()

Disables dynamic scaling functionality. See Also: #setDynamicScaling(int, int, Duration)

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setAffinityKeyLifetime(Duration affinityKeyLifetime)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setAffinityKeyLifetime(Duration affinityKeyLifetime)

How long to keep an affinity key after its last use. Zero value means keeping keys forever.

Parameter
Name Description
affinityKeyLifetime Duration

time since last use of a key to include the key in a cleanup.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setChannelPickStrategy(GcpManagedChannelOptions.ChannelPickStrategy strategy)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPickStrategy(GcpManagedChannelOptions.ChannelPickStrategy strategy)

Sets the strategy for picking the least busy channel from the pool.

Defaults to ChannelPickStrategy#POWER_OF_TWO which 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 ChannelPickStrategy#LINEAR_SCAN to restore the legacy behavior of scanning all channels and always picking the one with the lowest picker load.

Parameter
Name Description
strategy GcpManagedChannelOptions.ChannelPickStrategy

the channel pick strategy to use.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setChannelPrimeMaxAttempts(int channelPrimeMaxAttempts)

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.

Parameter
Name Description
channelPrimeMaxAttempts int
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setChannelPrimeTimeout(Duration channelPrimeTimeout)

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.

Parameter
Name Description
channelPrimeTimeout Duration
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setChannelPrimer(GcpChannelPrimer channelPrimer)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setChannelPrimer(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. A null primer disables priming and preserves the existing scale-up path.

Parameter
Name Description
channelPrimer GcpChannelPrimer
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setCleanupInterval(Duration cleanupInterval)

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.

Parameter
Name Description
cleanupInterval Duration

frequency of affinity key cleanup.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setConcurrentStreamsLowWatermark(int concurrentStreamsLowWatermark)

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.

Parameter
Name Description
concurrentStreamsLowWatermark int

number of streams every channel must reach before adding a new channel to the pool.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setDrainIdleGrace(Duration drainIdleGrace)

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.

Parameter
Name Description
drainIdleGrace Duration
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setDynamicScaling(int minRpcPerChannel, int maxRpcPerChannel, Duration scaleDownInterval)

Enables dynamic scaling functionality.

After a call is counted, load above maxRpcPerChannel on 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
Name Description
minRpcPerChannel int

minimum desired average concurrent calls per channel.

maxRpcPerChannel int

maximum desired average concurrent calls per channel.

scaleDownInterval Duration

how often to check for a possibility to scale down.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setErrorPenaltyDuration(Duration errorPenaltyDuration)

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.

Parameter
Name Description
errorPenaltyDuration Duration
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setErrorPenaltyStep(int errorPenaltyStep)

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 at maxRpcPerChannel. Must not be negative. Defaults to 5.

Parameter
Name Description
errorPenaltyStep int
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setInitSize(int initSize)

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.

Parameter
Name Description
initSize int

number of channels to start the pool with.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setMaxScaleDownChannels(int channels)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMaxScaleDownChannels(int channels)
Parameter
Name Description
channels int
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setMaxScaleUpPercent(int percent)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMaxScaleUpPercent(int percent)

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.

Parameter
Name Description
percent int
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setMaxSize(int maxSize)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMaxSize(int maxSize)

Sets the maximum size of the channel pool.

Parameter
Name Description
maxSize int

maximum number of channels the pool can have.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setMinSize(int minSize)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setMinSize(int minSize)

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.

Parameter
Name Description
minSize int

minimum number of channels the pool must have.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setScaleDownConsecutiveLowLoadChecks(int checks)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setScaleDownConsecutiveLowLoadChecks(int checks)
Parameter
Name Description
checks int
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setScaleUpCooldown(Duration scaleUpCooldown)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setScaleUpCooldown(Duration scaleUpCooldown)

Sets the minimum interval between successful scale-up operations. Zero uses the 10-second default.

Parameter
Name Description
scaleUpCooldown Duration
Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder

setUseRoundRobinOnBind(boolean enabled)

public GcpManagedChannelOptions.GcpChannelPoolOptions.Builder setUseRoundRobinOnBind(boolean enabled)

Enables/disables using round-robin channel selection for affinity binding calls.

Parameter
Name Description
enabled boolean

If true, use round-robin channel selection for affinity binding calls.

Returns
Type Description
GcpManagedChannelOptions.GcpChannelPoolOptions.Builder