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: f64Fill ratio threshold to trigger scale-up (0.0 - 1.0). Default: 0.7 (70%)
push_latency_threshold_ns: u64Push latency threshold in nanoseconds to trigger scale-up. Default: 5ns (after this, we’re seeing contention)
flush_latency_threshold_us: u64Batch flush latency threshold in microseconds to trigger scale-up. Default: 1000μs (1ms)
min_shards: u16Minimum number of shards (floor for scaling down).
max_shards: u16Maximum number of shards (ceiling for scaling up).
cooldown: DurationCooldown period between scaling operations. Default: 1 second
scale_down_delay: DurationHow long a shard must be underutilized before scaling down. Default: 10 seconds
underutilized_threshold: f64Fill ratio below which a shard is considered underutilized. Default: 0.1 (10%)
metrics_window: DurationMetrics collection window. Default: 100ms
auto_scale: boolEnable automatic scaling (if false, scaling is manual only).
Implementations§
Source§impl ScalingPolicy
impl ScalingPolicy
Sourcepub fn default_for_cpus(cpus: u16) -> Self
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.
Sourcepub fn high_throughput() -> Self
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).
Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Create a conservative policy for stable workloads.
Sourcepub fn normalize(self) -> Self
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.
Sourcepub fn validate(&self) -> Result<(), ConfigError>
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
impl Clone for ScalingPolicy
Source§fn clone(&self) -> ScalingPolicy
fn clone(&self) -> ScalingPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more