pub struct EnginePool { /* private fields */ }Expand description
A pool for reusing backend engine instances
Implementations§
Source§impl EnginePool
impl EnginePool
pub fn new(config: EnginePoolConfig) -> Self
Sourcepub async fn set_eviction_callback<F>(&self, cb: F)
pub async fn set_eviction_callback<F>(&self, cb: F)
Set an eviction callback that will be invoked whenever an engine is evicted. The callback receives (model_id, device_id, evicted_engine).
Sourcepub async fn clear_eviction_callback(&self)
pub async fn clear_eviction_callback(&self)
Clear any previously set eviction callback.
pub fn start_health_check_task(&self) -> JoinHandle<()>
pub fn max_size(&self) -> usize
pub fn min_size(&self) -> usize
pub fn ttl(&self) -> Duration
pub fn health_check_interval(&self) -> Duration
Sourcepub async fn get(
&self,
model_id: u32,
device_id: usize,
) -> Option<Arc<dyn Engine>>
pub async fn get( &self, model_id: u32, device_id: usize, ) -> Option<Arc<dyn Engine>>
Get an existing engine from the pool if available Returns None if engine doesn’t exist or fails health check
Sourcepub async fn put(
&self,
model_id: u32,
device_id: usize,
engine: Arc<dyn Engine>,
)
pub async fn put( &self, model_id: u32, device_id: usize, engine: Arc<dyn Engine>, )
Add an engine to the pool
If adding this engine causes an eviction, the eviction callback (if set) will be invoked asynchronously in a separate task to avoid blocking pool operations.
Sourcepub async fn remove(&self, model_id: u32, device_id: usize)
pub async fn remove(&self, model_id: u32, device_id: usize)
Remove an engine from the pool (e.g. on error or unload)
pub async fn len(&self) -> usize
pub async fn is_empty(&self) -> bool
Sourcepub async fn warmup<F, Fut>(
&self,
engine_configs: Vec<(u32, usize)>,
engine_factory: F,
) -> Result<(), EngineError>
pub async fn warmup<F, Fut>( &self, engine_configs: Vec<(u32, usize)>, engine_factory: F, ) -> Result<(), EngineError>
Warm up the pool by pre-creating engines
engine_factory is an async function that creates an engine for given (model_id, device_id)
pub async fn pool_metrics(&self) -> PoolMetrics
Trait Implementations§
Source§impl Clone for EnginePool
impl Clone for EnginePool
Source§fn clone(&self) -> EnginePool
fn clone(&self) -> EnginePool
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for EnginePool
impl !RefUnwindSafe for EnginePool
impl Send for EnginePool
impl Sync for EnginePool
impl Unpin for EnginePool
impl UnsafeUnpin for EnginePool
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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