pub struct SmartBatcher { /* private fields */ }Expand description
An adaptive batcher that groups PromptRequests into micro-batches.
See the module documentation for usage details.
Implementations§
Source§impl SmartBatcher
impl SmartBatcher
Sourcepub fn new(config: BatchConfig) -> Self
pub fn new(config: BatchConfig) -> Self
Create a new batcher with the given BatchConfig.
Sourcepub async fn submit(&self, request: PromptRequest) -> bool
pub async fn submit(&self, request: PromptRequest) -> bool
Submit a single PromptRequest to the staging buffer.
Returns true if submitting this request immediately triggered a
full-batch flush (i.e. poll_ready will
return Some on the next call).
Sourcepub async fn poll_ready(&self) -> Option<Vec<PromptRequest>>
pub async fn poll_ready(&self) -> Option<Vec<PromptRequest>>
Poll for a ready batch.
Returns Some(batch) when either:
- Any bucket has reached
BatchConfig::max_batch_size, or - Any bucket’s age exceeds
BatchConfig::max_wait_ms.
Returns None when no batch is ready yet. The caller should call
this in a loop with a short sleep (e.g. 1–5 ms) between iterations.
Sourcepub async fn flush_all(&self) -> Option<Vec<PromptRequest>>
pub async fn flush_all(&self) -> Option<Vec<PromptRequest>>
Force-flush all pending requests regardless of batch size or age.
Returns all requests across all buckets as a single flat batch, or
None if nothing is pending. Useful for graceful shutdown.
Sourcepub async fn pending_count(&self) -> usize
pub async fn pending_count(&self) -> usize
Number of requests currently sitting in staging buckets.
Sourcepub fn stats(&self) -> BatcherStats
pub fn stats(&self) -> BatcherStats
Snapshot of batcher statistics.
Trait Implementations§
Source§impl Clone for SmartBatcher
impl Clone for SmartBatcher
Source§fn clone(&self) -> SmartBatcher
fn clone(&self) -> SmartBatcher
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SmartBatcher
impl !UnwindSafe for SmartBatcher
impl Freeze for SmartBatcher
impl Send for SmartBatcher
impl Sync for SmartBatcher
impl Unpin for SmartBatcher
impl UnsafeUnpin for SmartBatcher
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request