Skip to main content

ControlUnit

Struct ControlUnit 

Source
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_rx carries the Decision the enforcement layer applies. Subscribers wake on every change so caps land promptly.
  • snapshot_rx carries a ControllerSnapshot for diagnostics — used by the progress bar and other UI surfaces. Snapshot-only changes (e.g. baseline drift on an unchanged cwnd) 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 published Decision.
  • 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>

Source

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.

Source

pub fn label(&self) -> &'static str

The label this unit was constructed with, used as the unit field on every emitted tracing event.

Source

pub fn spawn(self) -> JoinHandle<()>

Spawn the control loop on the current tokio runtime. Returns a JoinHandle that resolves when the sample channel closes.

Source

pub async fn run(self)

Run the control loop until the sample channel closes.

Auto Trait Implementations§

§

impl<C> Freeze for ControlUnit<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for ControlUnit<C>
where C: RefUnwindSafe,

§

impl<C> Send for ControlUnit<C>

§

impl<C> Sync for ControlUnit<C>
where C: Sync,

§

impl<C> Unpin for ControlUnit<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for ControlUnit<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for ControlUnit<C>
where C: UnwindSafe,

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