Available on crate feature
scaling only.Expand description
Scaling pressure calculation for autoscaler integration.
Produces a 0.0-100.0 composite metric based on weighted application signals with two hard gates (circuit breaker, memory pressure). Designed for KEDA but works with any autoscaler that reads Prometheus gauges.
§Architecture
App signals ──→ ScalingPressure ──→ {prefix}_scaling_pressure gauge
├─ Gate: circuit breaker open → 0.0
├─ Gate: memory ≥ threshold → 100.0
└─ Weighted composite → 0.0-100.0§Usage
- Define components with weights and saturation points
- Create
ScalingPressurewith base config + components - Update component values from your pipeline (lock-free)
- Call
calculate()when rendering Prometheus metrics
use hyperi_rustlib::scaling::{ScalingPressure, ScalingPressureConfig, ScalingComponent};
let pressure = ScalingPressure::new(
ScalingPressureConfig::default(),
vec![
ScalingComponent::new("kafka_lag", 0.35, 100_000.0),
ScalingComponent::new("buffer_depth", 0.25, 10_000.0),
ScalingComponent::new("memory", 0.40, 1.0),
],
);
// Update from pipeline (lock-free, call from any thread)
pressure.set_component("kafka_lag", 50_000.0);
pressure.set_memory(400_000_000, 1_000_000_000);
// Render in Prometheus endpoint
let value = pressure.calculate();
assert!(value >= 0.0 && value <= 100.0);§CPU Scaling
CPU is intentionally not included in the composite. KEDA’s native
CPU trigger reads from the Kubernetes metrics-server (container-level
CPU utilisation). Configure both triggers independently in your
KEDA ScaledObject:
scaling_pressuregauge → Prometheus scaler (app-level signals)- CPU utilisation → CPU scaler (container-level, via metrics-server)
KEDA scales to the MAX of all triggers.
Structs§
- Component
Snapshot - Per-component diagnostic snapshot.
- Pressure
Expr - A single named pressure expression -> one
{ns}_scaling_pressure{name=...}gauge. The autoscaler scales to the MAX across all enabled pressures. - Pressure
Snapshot - Full diagnostic snapshot of scaling pressure state.
- Pressure
Targets - Per-pod normalisation targets (KEDA
lagThreshold-style: “what ONE pod tolerates”). Pulled from the configparamsmap with researched defaults. - Rate
Window - Sliding window rate calculator.
- Scaling
Component - Named scaling component with weight and saturation point.
- Scaling
Engine - The CEL-over-local-metrics horizontal scaling-pressure engine.
- Scaling
Engine Config - Configuration for the horizontal scaling-pressure ENGINE (CEL over local metrics).
- Scaling
Pressure - Lock-free scaling pressure calculator.
- Scaling
Pressure Config - Base configuration for scaling pressure calculation.
- Scaling
Signals Cell - Lock-free cell the app / transport updates with the current per-pod signals;
the engine tick reads a
snapshot. A NaN bit-pattern means “absent” ->Nonein the snapshot (contributes 0 to the pressure). - Scaling
Transport Config - Optional explicit transport kinds for the compound pressure (
kafka,redis,http,grpc, …).None=> auto-derived by the runtime. - Transport
Signals - Per-pod, locally-knowable scaling signals, sampled each scaling tick.
Enums§
- Gate
Type - Active gate preventing normal composite calculation.
- Scaling
Transport - Inbound/outbound transport kind, for scaling-signal selection.
Functions§
- inbound_
pressure - Compound INBOUND pressure ratio (per-pod; >=0, unclamped above 1.0 for proportional scale-up). Picks the signal by the configured inbound kind.
- outbound_
pressure - Compound OUTBOUND pressure ratio (per-pod). EMIT-ONLY by default – NOT in the smart-default composite (downstream-bound; more pods rarely relieve a saturated sink – scaling ACR). A dead sink surfaces as the circuit gate in the composite, not here.