pub struct BatchProcessor { /* private fields */ }Expand description
Batch processor for high-throughput inference
Automatically batches incoming requests according to the configured strategy, executes them in a single forward pass, and returns individual results.
§Performance
- Static batching: 3-5x throughput for stable workloads
- Dynamic batching: 5-10x throughput with variable request rates
- Optimal for GPU inference where batch processing is highly efficient
§Example
ⓘ
use ronn_api::{Model, SessionOptions, BatchProcessor, BatchConfig, BatchStrategy};
use std::collections::HashMap;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let model = Model::load("model.onnx")?;
let session = model.create_session(SessionOptions::default())?;
let config = BatchConfig {
strategy: BatchStrategy::Dynamic {
max_batch_size: 32,
timeout_ms: 10,
},
..Default::default()
};
let processor = BatchProcessor::new(session, config);
// Submit requests - they will be automatically batched
let inputs = HashMap::new(); // Add your inputs here
let output = processor.process(inputs).await?;
Ok(())
}Implementations§
Source§impl BatchProcessor
impl BatchProcessor
Auto Trait Implementations§
impl Freeze for BatchProcessor
impl RefUnwindSafe for BatchProcessor
impl Send for BatchProcessor
impl Sync for BatchProcessor
impl Unpin for BatchProcessor
impl UnwindSafe for BatchProcessor
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