Skip to main content

ModelSwitcher

Struct ModelSwitcher 

Source
pub struct ModelSwitcher { /* private fields */ }
Expand description

The model switcher coordinates wake/sleep transitions

Implementations§

Source§

impl ModelSwitcher

Source

pub fn new( orchestrator: Arc<Orchestrator>, policy: Box<dyn SwitchPolicy>, ) -> Self

Create a new model switcher

Source

pub async fn state(&self) -> SwitcherState

Get the current state

Source

pub async fn active_model(&self) -> Option<String>

Get the currently active model

Source

pub async fn mode(&self) -> SwitchMode

Get the current switch mode

Source

pub async fn set_mode(&self, mode: SwitchMode)

Set the switch mode

Source

pub fn registered_models(&self) -> Vec<String>

Get the list of registered model names

Source

pub fn orchestrator(&self) -> &Arc<Orchestrator>

Get access to the orchestrator (for process state queries)

Source

pub fn policy_eviction(&self) -> EvictionPolicy

Get the policy’s default eviction policy

Source

pub async fn force_switch(&self, model: &str) -> Result<(), SwitchError>

Force a switch to the given model, bypassing policy.

Reuses the full do_switch machinery (drain, sleep, wake) so all safety guarantees still apply. Returns after the switch completes.

Source

pub fn is_registered(&self, model: &str) -> bool

Check if a model is registered

Source

pub fn in_flight_count(&self, model: &str) -> usize

Get in-flight count for a model

Source

pub async fn ensure_model_ready(&self, model: &str) -> Result<(), SwitchError>

Ensure a model is ready for requests

This will:

  1. Return immediately if the model is already active
  2. In manual mode: reject if model doesn’t match pinned/active model
  3. Queue the request and trigger a switch if needed
  4. Wait for the switch to complete (up to timeout)
Source

pub fn acquire_in_flight(&self, model: &str) -> Option<InFlightGuard>

Acquire an in-flight guard.

Returns None if the model is not registered or if the model is currently draining (about to be put to sleep). Uses increment-then-check to close the TOCTOU window between notify_pending and the drain in do_switch.

Source

pub async fn queue_depths(&self) -> HashMap<String, usize>

Get the queue depth for every registered model.

Source

pub fn spawn_scheduler(self) -> Option<JoinHandle<()>>

Spawn a background scheduler task if the policy requests one.

Returns Some(JoinHandle) if the scheduler was spawned, None if the policy does not use a scheduler (i.e. scheduler_interval returns None).

Trait Implementations§

Source§

impl Clone for ModelSwitcher

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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