pub struct BatchProcessor<T: Send + 'static> { /* private fields */ }Expand description
Batch processor for inference requests
Implementations§
Source§impl<T: Send + 'static> BatchProcessor<T>
impl<T: Send + 'static> BatchProcessor<T>
Sourcepub fn new(config: BatchConfig) -> Self
pub fn new(config: BatchConfig) -> Self
Create a new batch processor
Sourcepub async fn submit(&self, payload: T) -> Result<BatchResult<T>, BatchError>
pub async fn submit(&self, payload: T) -> Result<BatchResult<T>, BatchError>
Submit a request and wait for the result
Sourcepub async fn run<F, Fut>(&self, executor: F)
pub async fn run<F, Fut>(&self, executor: F)
Run the dynamic-batching serving loop: wait for a batch, collect it, run
executor on the payloads, and deliver each request’s response.
This is the piece that makes BatchProcessor::submit resolve — without
a running run (or manual collect_batch/complete_batch), submitted
futures never complete. It is the serving primitive an inference/expert
worker spawns as a task; it loops until the task is cancelled.
executor receives the batched payloads in arrival order and must return
exactly one response per input, in the same order. (If it returns fewer,
the surplus requests are cancelled rather than answered.)
let p = processor.clone();
tokio::spawn(async move {
p.run(|batch: Vec<Req>| async move { model.forward(batch).await }).await;
});
let result = processor.submit(req).await?; // resolved by the loopSourcepub fn stats(&self) -> BatchStats
pub fn stats(&self) -> BatchStats
Get batch statistics
Sourcepub fn collect_batch(&self) -> Vec<(T, Sender<BatchResult<T>>, Instant)>
pub fn collect_batch(&self) -> Vec<(T, Sender<BatchResult<T>>, Instant)>
Collect a batch of requests (up to max_batch_size)
Sourcepub fn complete_batch(&self, results: Vec<(Sender<BatchResult<T>>, Instant, T)>)
pub fn complete_batch(&self, results: Vec<(Sender<BatchResult<T>>, Instant, T)>)
Complete a batch with results.
Each entry is (response_sender, arrival_instant, response_payload).
Sourcepub async fn wait_for_batch(&self) -> bool
pub async fn wait_for_batch(&self) -> bool
Wait for a batch to be ready