pub struct ControlUnit<C: Controller> { /* private fields */ }Expand description
A single resource’s control task.
Construct with ControlUnit::new, receive the decision and snapshot
watches via the returned (unit, decision_rx, snapshot_rx) tuple, then
spawn the unit with ControlUnit::spawn. The task runs until the
sample channel’s senders are all dropped (typically because
clear_sample_sink was called and the
RoutingSink went away).
§Watches
Two watches keep enforcement and observability separate:
decision_rxcarries theDecisionthe enforcement layer applies. Subscribers wake on every change so caps land promptly.snapshot_rxcarries aControllerSnapshotfor diagnostics — used by the progress bar and other UI surfaces. Snapshot-only changes (e.g. baseline drift on an unchangedcwnd) do not wake enforcement, and a busy enforcement subscriber does not stall snapshot publication.
§Logging
Each unit emits structured tracing events keyed by its label so
multiple units can be told apart in mixed logs:
tracing::trace!on every tick with the publishedDecision.tracing::debug!whenever the published decision differs from the prior tick’s. This is the right level for watching cwnd evolve in production without drowning in per-tick noise.
Implementations§
Source§impl<C: Controller + 'static> ControlUnit<C>
impl<C: Controller + 'static> ControlUnit<C>
Sourcepub fn new(
label: &'static str,
controller: C,
sample_rx: Receiver<Sample>,
tick_interval: Duration,
) -> (Self, Receiver<Decision>, Receiver<ControllerSnapshot>)
pub fn new( label: &'static str, controller: C, sample_rx: Receiver<Sample>, tick_interval: Duration, ) -> (Self, Receiver<Decision>, Receiver<ControllerSnapshot>)
Build a new control unit. Returns the unit, a receiver for its
decision stream, and a receiver for its snapshot stream. The
initial decision is Decision::UNLIMITED and the initial
snapshot is ControllerSnapshot::default until the first tick
fires.
label is a short, stable string that identifies this unit in
log events and in the snapshot registry (e.g. "meta-src",
"meta-dst"). Multiple units of the same controller type are
typical, so using only the controller name would make logs
ambiguous.
Sourcepub fn label(&self) -> &'static str
pub fn label(&self) -> &'static str
The label this unit was constructed with, used as the
unit field on every emitted tracing event.
Sourcepub fn spawn(self) -> JoinHandle<()>
pub fn spawn(self) -> JoinHandle<()>
Spawn the control loop on the current tokio runtime. Returns a
JoinHandle that resolves when the sample channel closes.