Skip to main content

DynamicChannelPoolConfig

Struct DynamicChannelPoolConfig 

Source
#[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

Source

pub fn new() -> Self

Creates a new default dynamic channel pool configuration.

§Example
let client = Spanner::builder()
    .with_channel_pool(DynamicChannelPoolConfig::new())
    .build()
    .await?;
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn initial_channels(&self) -> usize

Returns the number of channels created eagerly at startup.

Source

pub fn min_channels(&self) -> usize

Returns the minimum number of channels retained during scale-down.

Source

pub fn max_channels(&self) -> usize

Returns the maximum number of channels allowed during scale-up.

Source

pub fn min_rpc_per_channel(&self) -> f64

Returns the low-load threshold (per channel) triggering scale-down evaluation.

Source

pub fn max_rpc_per_channel(&self) -> f64

Returns the high-load threshold (per channel) triggering scale-up.

Source

pub fn error_penalty_step(&self) -> u32

Returns the synthetic picker load added per qualifying transport error.

Source

pub fn error_penalty_duration(&self) -> Duration

Returns the sliding window duration for active error penalties.

Source

pub fn scale_down_check_interval(&self) -> Duration

Returns the interval between periodic scale-down evaluations.

Source

pub fn scale_up_cooldown(&self) -> Duration

Returns the cooldown period between consecutive scale-up bursts.

Source

pub fn consecutive_low_load_checks(&self) -> usize

Returns the number of consecutive low-load checks required before scale-down.

Source

pub fn max_scale_up_percent(&self) -> u32

Returns the maximum percentage of current pool size added per scale-up event.

Source

pub fn max_remove_channels(&self) -> usize

Returns the maximum number of channels marked draining per scale-down cycle.

Source

pub fn drain_idle_grace(&self) -> Duration

Returns the idle grace duration a draining channel is kept alive after load drops to zero.

Source

pub fn prime_timeout(&self) -> Duration

Returns the timeout for executing SELECT 1 priming on a new scaled-up channel.

Source

pub fn prime_max_attempts(&self) -> usize

Returns the maximum retry attempts for SELECT 1 priming.

Trait Implementations§

Source§

impl Clone for DynamicChannelPoolConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DynamicChannelPoolConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DynamicChannelPoolConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<DynamicChannelPoolConfig> for ChannelPoolConfig

Source§

fn from(config: DynamicChannelPoolConfig) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DynamicChannelPoolConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DynamicChannelPoolConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more