pub struct PoolBuilder<W, C>{ /* private fields */ }
Expand description
A struct to make building up a Pool simpler. The builder should be constructed using
PoolBuilder::new
, which provides the user control over the sizes of the queues used for
compression and writing. It should be noted that a single compression queue is created,
and one writer queue per writer exchanged. A good starting point for these queue sizes is
two times the number of threads.
Once created various functions can configure aspects of the pool. It is best practice, though
not required, to configure the builder before exchanging writers. The exception is
queue_size
that may not be set after any writers have been exchanged. If not set manually
then queue_size
defaults to the number of threads multiplied by
PoolBuilder::QUEUE_SIZE_THREAD_MULTIPLES
.
Once the builder is configured writers may be exchanged for PooledWriter
s using the
PoolBuilder::exchange
function, which consumes the provided writer and returns a new
writer that can be used in it’s place.
After exchanging all writers the pool may be created and started with PoolBuilder::build
which consumes the builder and after which no more writers may be exchanged.
Implementations§
Source§impl<W, C> PoolBuilder<W, C>
impl<W, C> PoolBuilder<W, C>
Sourcepub const QUEUE_SIZE_THREAD_MULTIPLES: usize = 50usize
pub const QUEUE_SIZE_THREAD_MULTIPLES: usize = 50usize
By default queue sizes will be set to threads * this constant.
Sourcepub const DEFAULT_THREADS: usize = 4usize
pub const DEFAULT_THREADS: usize = 4usize
The default number of threads that will be used if not otherwise configured
Sourcepub fn threads(self, threads: usize) -> Self
pub fn threads(self, threads: usize) -> Self
Sets the number of threads that will be used by the [Pool].
Will panic if set to 0.
Sourcepub fn queue_size(self, queue_size: usize) -> Self
pub fn queue_size(self, queue_size: usize) -> Self
Sets the size of queues used by the pool [Pool]. The same size is used for a) the queue of byte buffers to be compressed, b) the per-sample queues to receive compressed bytes, and c) a control queue to manage writing to the underlying writers.
In the worst case scenario the pool can be holding both queue_size uncompressed blocks and queue_size compressed blocks in memory when it cannot keep up with the incoming load of writes.
Will panic if called after writers have been created because queues will already have been created.
Sourcepub fn compression_level(self, level: u8) -> Result<Self, PoolError>
pub fn compression_level(self, level: u8) -> Result<Self, PoolError>
Sets the compression level that will be used by the [Pool].
Sourcepub fn exchange(&mut self, writer: W) -> PooledWriter ⓘ
pub fn exchange(&mut self, writer: W) -> PooledWriter ⓘ
Exchanges a writer for a [PooledWriter].