pub struct AdaptiveBatcher { /* private fields */ }Expand description
Adaptive batch size controller
Tracks recent inference latencies and adjusts the recommended batch size to keep per-batch latency near the configured target.
Implementations§
Source§impl AdaptiveBatcher
impl AdaptiveBatcher
Sourcepub fn new(config: AdaptiveBatchConfig) -> Self
pub fn new(config: AdaptiveBatchConfig) -> Self
Create a new AdaptiveBatcher starting at min_batch_size.
Sourcepub fn recommended_batch_size(&self) -> usize
pub fn recommended_batch_size(&self) -> usize
Return the current recommended batch size.
Sourcepub fn update_latency(&mut self, latency_ms: f64, batch_size: usize)
pub fn update_latency(&mut self, latency_ms: f64, batch_size: usize)
Update the batch-size estimate based on the observed latency for a completed batch.
§Parameters
latency_ms: wall-clock time the batch took in millisecondsbatch_size: number of items that were in the completed batch
Sourcepub fn create_batches(
&self,
requests: Vec<PredictionRequest>,
) -> Vec<Vec<PredictionRequest>>
pub fn create_batches( &self, requests: Vec<PredictionRequest>, ) -> Vec<Vec<PredictionRequest>>
Group a flat list of requests into batches, each of at most
recommended_batch_size() items.
Sourcepub fn average_latency_ms(&self) -> f64
pub fn average_latency_ms(&self) -> f64
Rolling average latency over the recent observation window.
Returns 0.0 when no observations have been recorded yet.
Sourcepub fn total_batches(&self) -> u64
pub fn total_batches(&self) -> u64
Total number of completed batches.
Sourcepub fn total_items(&self) -> u64
pub fn total_items(&self) -> u64
Total number of individual items processed across all batches.
Sourcepub fn config(&self) -> &AdaptiveBatchConfig
pub fn config(&self) -> &AdaptiveBatchConfig
Return a reference to the current configuration.
Auto Trait Implementations§
impl Freeze for AdaptiveBatcher
impl RefUnwindSafe for AdaptiveBatcher
impl Send for AdaptiveBatcher
impl Sync for AdaptiveBatcher
impl Unpin for AdaptiveBatcher
impl UnsafeUnpin for AdaptiveBatcher
impl UnwindSafe for AdaptiveBatcher
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> 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