pub struct BufferPool { /* private fields */ }Expand description
Lock-free buffer pool for reusing large I/O buffers.
Uses bounded ArrayQueues so queue slots are allocated once at startup and
buffer return does not allocate linked queue blocks on the forwarding path.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(buffer_size: BufferSize, max_pool_size: usize) -> Self
pub fn new(buffer_size: BufferSize, max_pool_size: usize) -> Self
Create a new lazy buffer pool
§Arguments
buffer_size- Size of each buffer in bytes (must be non-zero)max_pool_size- Maximum number of buffers to pool
§Design Philosophy
Buffer pool queue capacity is allocated once at application boot. Backing buffers are allocated lazily as clients/backend work first need them, then returned to the pool for reuse. This is a critical performance optimization:
- Boot time: Queue slots only; idle RSS stays small
- Warm runtime: Zero allocations in hot path (acquire/release from pool)
- Per-connection: Buffers are borrowed and returned, never owned
IMPORTANT: Do NOT create a BufferPool per-client, per-connection, or
per-request. Create ONE pool at application startup and share it across
all operations via Arc or static reference.
Buffers are allocated on first use up to max_pool_size; allocations beyond
that remain visible through fallback metrics.
Sourcepub fn with_capture_pool(self, capacity: usize, count: usize) -> Self
pub fn with_capture_pool(self, capacity: usize, count: usize) -> Self
Configure the capture buffer pool for accumulator buffers
Capture buffers are used for accumulating streaming data (e.g., caching).
§Arguments
capacity- Size of each capture buffer in bytes (e.g., 1 MiB by default)count- Maximum number of capture buffers to pool
Sourcepub fn available_buffers(&self) -> usize
pub fn available_buffers(&self) -> usize
Get the current number of available buffers in the pool
Sourcepub fn buffers_in_use(&self) -> usize
pub fn buffers_in_use(&self) -> usize
Get the number of buffers currently in use
Sourcepub fn stats(&self) -> (usize, usize, usize)
pub fn stats(&self) -> (usize, usize, usize)
Get buffer pool statistics (available, in-use, total)
pub fn acquire(&self) -> PooledBuffer
pub fn acquire_capture(&self) -> PooledBuffer
Trait Implementations§
Source§impl Clone for BufferPool
impl Clone for BufferPool
Source§fn clone(&self) -> BufferPool
fn clone(&self) -> BufferPool
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 Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl UnwindSafe for BufferPool
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
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> ⓘ
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> ⓘ
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