pub struct EnginePool { /* private fields */ }Expand description
A pool of InferenceEngine replicas guarded by a semaphore.
Construct with EnginePool::new; acquire an engine with
EnginePool::acquire. The returned EngineLease derefs to the engine
and returns it to the pool on drop.
Implementations§
Source§impl EnginePool
impl EnginePool
Sourcepub fn new(engines: Vec<InferenceEngine<'static>>) -> Arc<Self>
pub fn new(engines: Vec<InferenceEngine<'static>>) -> Arc<Self>
Build a pool from a vector of engine replicas.
The pool size is engines.len(), guaranteed to be at least 1 (an
empty input yields a 1-permit pool with no engines, which would only
ever return PoolError::Empty; callers must pass at least one
engine). The semaphore is seeded with size permits.
Sourcepub fn set_metrics_all(
&self,
metrics: &Arc<InferenceMetrics>,
) -> Result<(), PoolError>
pub fn set_metrics_all( &self, metrics: &Arc<InferenceMetrics>, ) -> Result<(), PoolError>
Attach a shared crate::metrics::InferenceMetrics to every replica in the pool.
This wires the per-engine telemetry (prefill / decode-token /
tokens-per-second histograms recorded inside generate*) onto each
replica, mirroring the single-engine engine.set_metrics(..) call the
CLI serve handler performed before this pool existed. It must be called
while the pool is idle (right after construction, before any lease is
handed out), so all replicas are present in idle.
Returns PoolError::Poisoned if the idle mutex was poisoned. The
metrics Arc is cloned once per replica so they all share one instance.
Sourcepub async fn acquire(self: &Arc<Self>) -> Result<EngineLease, PoolError>
pub async fn acquire(self: &Arc<Self>) -> Result<EngineLease, PoolError>
Acquire an engine from the pool, waiting asynchronously if all replicas are currently in use.
Returns an EngineLease that derefs to the engine and returns it to
the pool on drop. The acquired permit is held for the lease’s lifetime.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EnginePool
impl !RefUnwindSafe for EnginePool
impl !UnwindSafe for EnginePool
impl Send for EnginePool
impl Sync for EnginePool
impl Unpin for EnginePool
impl UnsafeUnpin for EnginePool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more