Skip to main content

ScalingPolicy

Struct ScalingPolicy 

Source
pub struct ScalingPolicy {
    pub fill_ratio_threshold: f64,
    pub push_latency_threshold_ns: u64,
    pub flush_latency_threshold_us: u64,
    pub min_shards: u16,
    pub max_shards: u16,
    pub cooldown: Duration,
    pub scale_down_delay: Duration,
    pub underutilized_threshold: f64,
    pub metrics_window: Duration,
    pub auto_scale: bool,
}
Expand description

Policy configuration for dynamic shard scaling.

Fields§

§fill_ratio_threshold: f64

Fill ratio threshold to trigger scale-up (0.0 - 1.0). Default: 0.7 (70%)

§push_latency_threshold_ns: u64

Push latency threshold in nanoseconds to trigger scale-up. Default: 5ns (after this, we’re seeing contention)

§flush_latency_threshold_us: u64

Batch flush latency threshold in microseconds to trigger scale-up. Default: 1000μs (1ms)

§min_shards: u16

Minimum number of shards (floor for scaling down).

§max_shards: u16

Maximum number of shards (ceiling for scaling up).

§cooldown: Duration

Cooldown period between scaling operations. Default: 1 second

§scale_down_delay: Duration

How long a shard must be underutilized before scaling down. Default: 10 seconds

§underutilized_threshold: f64

Fill ratio below which a shard is considered underutilized. Default: 0.1 (10%)

§metrics_window: Duration

Metrics collection window. Default: 100ms

§auto_scale: bool

Enable automatic scaling (if false, scaling is manual only).

Implementations§

Source§

impl ScalingPolicy

Source

pub fn default_for_cpus(cpus: u16) -> Self

Create a default scaling policy based on CPU count. Scales from 1 shard up to the number of physical cores.

Source

pub fn high_throughput() -> Self

Create a policy optimized for high-throughput GPU workloads. Uses more aggressive scaling with higher max shard count.

max_shards is capped at u16::MAX (65 535) because shard ids are 16-bit. On hosts with more than 32 767 CPUs the “2× CPU count” target saturates rather than wraps — this is the intended behavior (pre-fix this was just an implicit saturating_mul artifact; the cap is now documented and the saturation is explicit).

Source

pub fn conservative() -> Self

Create a conservative policy for stable workloads.

Source

pub fn normalize(self) -> Self

Normalize the policy by auto-adjusting conflicting values.

This allows users to set either min_shards or max_shards independently without worrying about the other. If max_shards < min_shards, max_shards is adjusted to equal min_shards.

Source

pub fn validate(&self) -> Result<(), ConfigError>

Validate the policy.

is_finite() guards reject NaN and ±∞ explicitly before the range check runs. NaN thresholds slip past raw <= / > comparisons (every comparison against f64::NaN returns false), so a config deserialized from 0.0/0.0-style arithmetic or an unfortunate environment-templated string would “validate” successfully and then sit inert at runtime — mapper.rs:560 does m.fill_ratio > self.policy.fill_ratio_threshold, which is always false against NaN, so the scaler would never fire (mirror hazard for scale-down).

Trait Implementations§

Source§

impl Clone for ScalingPolicy

Source§

fn clone(&self) -> ScalingPolicy

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 ScalingPolicy

Source§

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

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

impl Default for ScalingPolicy

Source§

fn default() -> Self

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

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<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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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