pooled_writer

Struct PoolBuilder

Source
pub struct PoolBuilder<W, C>
where W: Write + Send + 'static, C: Compressor,
{ /* 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 PooledWriters 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>
where W: Write + Send + 'static, C: Compressor,

Source

pub const QUEUE_SIZE_THREAD_MULTIPLES: usize = 50usize

By default queue sizes will be set to threads * this constant.

Source

pub const DEFAULT_THREADS: usize = 4usize

The default number of threads that will be used if not otherwise configured

Source

pub fn new() -> Self

Creates a new PoolBuilder that can be used to configure and build a Pool.

Source

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.

Source

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.

Source

pub fn compression_level(self, level: u8) -> Result<Self, PoolError>

Sets the compression level that will be used by the [Pool].

Source

pub fn exchange(&mut self, writer: W) -> PooledWriter

Exchanges a writer for a [PooledWriter].

Source

pub fn build(self) -> Result<Pool, PoolError>

Consumes the builder and generates the [Pool] ready for use.

Trait Implementations§

Source§

impl<W, C> Default for PoolBuilder<W, C>
where W: Write + Send + 'static, C: Compressor,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<W, C> Freeze for PoolBuilder<W, C>

§

impl<W, C> RefUnwindSafe for PoolBuilder<W, C>

§

impl<W, C> Send for PoolBuilder<W, C>

§

impl<W, C> Sync for PoolBuilder<W, C>
where <C as Compressor>::CompressionLevel: Sync, W: Sync,

§

impl<W, C> Unpin for PoolBuilder<W, C>

§

impl<W, C> UnwindSafe for PoolBuilder<W, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.