mod controller;
mod egress;
mod resource_pressure;
mod state;
pub use controller::LoadShedController;
pub use egress::EgressMeter;
pub use resource_pressure::{Params as ResourcePressureParams, ResourcePressure};
pub use state::{ShedSlot, ShedState};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RequestClass {
CacheHit,
CacheMiss,
}
#[derive(Debug, Clone, Copy)]
pub struct PressureSnapshot {
pub streams_in_flight: u32,
pub client_streams_in_flight: u32,
pub egress_bps: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShedReason {
NodeAtCapacity,
EgressSaturated,
ClientAtCapacity,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShedDecision {
Admit,
Shed(ShedReason),
}
pub trait LoadShedPolicy: Send + Sync {
fn decide(&self, class: RequestClass, snap: &PressureSnapshot) -> ShedDecision;
fn pressure_active(&self) -> bool {
false
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct AlwaysAdmit;
impl LoadShedPolicy for AlwaysAdmit {
fn decide(&self, _class: RequestClass, _snap: &PressureSnapshot) -> ShedDecision {
ShedDecision::Admit
}
}
#[cfg(test)]
mod tests;