#[non_exhaustive]pub struct DynamicChannelPoolConfig { /* private fields */ }Expand description
Configuration for a dynamically scaling channel pool.
§Example
let config = DynamicChannelPoolConfig::new()
.with_initial_channels(4)
.with_min_channels(2)
.with_max_channels(16);
let client = Spanner::builder()
.with_channel_pool(config)
.build()
.await?;Manages elastic scaling of gRPC channels based on in-flight RPC load and error feedback.
Implementations§
Source§impl DynamicChannelPoolConfig
impl DynamicChannelPoolConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new default dynamic channel pool configuration.
§Example
let client = Spanner::builder()
.with_channel_pool(DynamicChannelPoolConfig::new())
.build()
.await?;Sourcepub fn with_initial_channels(self, channels: usize) -> Self
pub fn with_initial_channels(self, channels: usize) -> Self
Sets the number of channels created eagerly at startup.
Defaults to 4. Must be between min_channels and max_channels.
Sourcepub fn with_min_channels(self, channels: usize) -> Self
pub fn with_min_channels(self, channels: usize) -> Self
Sets the minimum number of channels retained during scale-down.
Defaults to 4. Must be at least 1 and cannot exceed max_channels.
Sourcepub fn with_max_channels(self, channels: usize) -> Self
pub fn with_max_channels(self, channels: usize) -> Self
Sets the maximum number of channels allowed during scale-up.
Defaults to 256 (maximum supported limit: 256). Must be greater than or equal to min_channels.
Sourcepub fn with_min_rpc_per_channel(self, min_rpc: f64) -> Self
pub fn with_min_rpc_per_channel(self, min_rpc: f64) -> Self
Sets the low-load threshold (in active RPCs per channel) triggering scale-down evaluation.
Defaults to 2.0. When average load across all channels drops below this value for
consecutive checks, the pool initiates scale-down. Must be a finite positive number
less than max_rpc_per_channel.
Sourcepub fn with_max_rpc_per_channel(self, max_rpc: f64) -> Self
pub fn with_max_rpc_per_channel(self, max_rpc: f64) -> Self
Sets the high-load threshold (in active RPCs per channel) triggering scale-up.
Defaults to 8.0. When load on any channel or average pool load exceeds this value,
the pool triggers scale-up. Must be a finite positive number strictly greater than
min_rpc_per_channel.
Sourcepub fn with_error_penalty_step(self, step: u32) -> Self
pub fn with_error_penalty_step(self, step: u32) -> Self
Sets the synthetic picker load added per qualifying transport error.
Defaults to 2. When a channel encounters a transport error, synthetic picker load is added
to steer traffic away from the problematic channel. Cannot exceed ceil(max_rpc_per_channel).
Sourcepub fn with_error_penalty_duration(self, duration: Duration) -> Self
pub fn with_error_penalty_duration(self, duration: Duration) -> Self
Sets the sliding window duration for active error penalties.
Defaults to 5 seconds. Each qualifying transport error resets the duration. When the duration elapses without further errors, accumulated error penalties decay to zero.
Sourcepub fn with_scale_down_check_interval(self, interval: Duration) -> Self
pub fn with_scale_down_check_interval(self, interval: Duration) -> Self
Sets the interval between periodic scale-down evaluations.
Defaults to 60 seconds (1 minute). A background worker inspects channel utilization at this interval. Must be greater than zero.
Sourcepub fn with_scale_up_cooldown(self, cooldown: Duration) -> Self
pub fn with_scale_up_cooldown(self, cooldown: Duration) -> Self
Sets the cooldown period between consecutive scale-up bursts.
Defaults to 1 second. Prevents repeated scale-up bursts from stampeding connection allocations before newly created channels can initialize and prime.
Sourcepub fn with_consecutive_low_load_checks(self, checks: usize) -> Self
pub fn with_consecutive_low_load_checks(self, checks: usize) -> Self
Sets the number of consecutive low-load checks required before scale-down.
Defaults to 3 checks (debouncing scale-down over 3 check intervals). Prevents rapid pool oscillation during intermittent traffic drops. Must be at least 1.
Sourcepub fn with_max_scale_up_percent(self, percent: u32) -> Self
pub fn with_max_scale_up_percent(self, percent: u32) -> Self
Sets the maximum percentage of current pool size added per scale-up event.
Defaults to 100% (with an internal minimum of 2 channels). Caps the rate of channel expansion to avoid connection storms against backend endpoints. Must be between 1 and 100.
Sourcepub fn with_max_remove_channels(self, max_channels: usize) -> Self
pub fn with_max_remove_channels(self, max_channels: usize) -> Self
Sets the maximum number of channels marked draining per scale-down cycle.
Defaults to 4 channels. Limits how aggressively channels are phased out in a single scale-down pass. Must be at least 1.
Sourcepub fn with_drain_idle_grace(self, grace: Duration) -> Self
pub fn with_drain_idle_grace(self, grace: Duration) -> Self
Sets the idle grace duration a draining channel is kept alive after load drops to zero.
Defaults to 60 seconds (1 minute). Ensures in-flight transactions with think time between statements have sufficient buffer to complete before the channel is terminated.
Sourcepub fn with_prime_timeout(self, timeout: Duration) -> Self
pub fn with_prime_timeout(self, timeout: Duration) -> Self
Sets the timeout for executing SELECT 1 priming on a new scaled-up channel.
Defaults to 5 seconds. Before a newly scaled-up channel is published to the active pool,
it is warmed up with a SELECT 1 query. If priming times out, the channel is discarded
and scale-up will be re-attempted. Must be greater than zero.
Sourcepub fn with_prime_max_attempts(self, attempts: usize) -> Self
pub fn with_prime_max_attempts(self, attempts: usize) -> Self
Sets the maximum retry attempts for SELECT 1 priming.
Defaults to 3 attempts. Bounds priming retries before abandoning the scaled-up channel. Must be at least 1.
Sourcepub fn initial_channels(&self) -> usize
pub fn initial_channels(&self) -> usize
Returns the number of channels created eagerly at startup.
Sourcepub fn min_channels(&self) -> usize
pub fn min_channels(&self) -> usize
Returns the minimum number of channels retained during scale-down.
Sourcepub fn max_channels(&self) -> usize
pub fn max_channels(&self) -> usize
Returns the maximum number of channels allowed during scale-up.
Sourcepub fn min_rpc_per_channel(&self) -> f64
pub fn min_rpc_per_channel(&self) -> f64
Returns the low-load threshold (per channel) triggering scale-down evaluation.
Sourcepub fn max_rpc_per_channel(&self) -> f64
pub fn max_rpc_per_channel(&self) -> f64
Returns the high-load threshold (per channel) triggering scale-up.
Sourcepub fn error_penalty_step(&self) -> u32
pub fn error_penalty_step(&self) -> u32
Returns the synthetic picker load added per qualifying transport error.
Sourcepub fn error_penalty_duration(&self) -> Duration
pub fn error_penalty_duration(&self) -> Duration
Returns the sliding window duration for active error penalties.
Sourcepub fn scale_down_check_interval(&self) -> Duration
pub fn scale_down_check_interval(&self) -> Duration
Returns the interval between periodic scale-down evaluations.
Sourcepub fn scale_up_cooldown(&self) -> Duration
pub fn scale_up_cooldown(&self) -> Duration
Returns the cooldown period between consecutive scale-up bursts.
Sourcepub fn consecutive_low_load_checks(&self) -> usize
pub fn consecutive_low_load_checks(&self) -> usize
Returns the number of consecutive low-load checks required before scale-down.
Sourcepub fn max_scale_up_percent(&self) -> u32
pub fn max_scale_up_percent(&self) -> u32
Returns the maximum percentage of current pool size added per scale-up event.
Sourcepub fn max_remove_channels(&self) -> usize
pub fn max_remove_channels(&self) -> usize
Returns the maximum number of channels marked draining per scale-down cycle.
Sourcepub fn drain_idle_grace(&self) -> Duration
pub fn drain_idle_grace(&self) -> Duration
Returns the idle grace duration a draining channel is kept alive after load drops to zero.
Sourcepub fn prime_timeout(&self) -> Duration
pub fn prime_timeout(&self) -> Duration
Returns the timeout for executing SELECT 1 priming on a new scaled-up channel.
Sourcepub fn prime_max_attempts(&self) -> usize
pub fn prime_max_attempts(&self) -> usize
Returns the maximum retry attempts for SELECT 1 priming.
Trait Implementations§
Source§impl Clone for DynamicChannelPoolConfig
impl Clone for DynamicChannelPoolConfig
Source§impl Debug for DynamicChannelPoolConfig
impl Debug for DynamicChannelPoolConfig
Source§impl Default for DynamicChannelPoolConfig
impl Default for DynamicChannelPoolConfig
Source§impl From<DynamicChannelPoolConfig> for ChannelPoolConfig
impl From<DynamicChannelPoolConfig> for ChannelPoolConfig
Source§fn from(config: DynamicChannelPoolConfig) -> Self
fn from(config: DynamicChannelPoolConfig) -> Self
Source§impl PartialEq for DynamicChannelPoolConfig
impl PartialEq for DynamicChannelPoolConfig
impl StructuralPartialEq for DynamicChannelPoolConfig
Auto Trait Implementations§
impl Forget for DynamicChannelPoolConfig
impl Freeze for DynamicChannelPoolConfig
impl Move for DynamicChannelPoolConfig
impl RefUnwindSafe for DynamicChannelPoolConfig
impl Send for DynamicChannelPoolConfig
impl Sync for DynamicChannelPoolConfig
impl Unpin for DynamicChannelPoolConfig
impl UnsafeUnpin for DynamicChannelPoolConfig
impl UnwindSafe for DynamicChannelPoolConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request