Skip to main content

Pipeline

Struct Pipeline 

Source
pub struct Pipeline<T: Send + 'static> { /* private fields */ }
Expand description

One class’s standing fan: N workers, built once, parked until there is work.

Implementations§

Source§

impl<T: Send + 'static> Pipeline<T>

Source

pub fn start<F>( class: OpClass, workers: usize, depth: usize, run: F, ) -> Pipeline<T>
where F: Fn(T) + Send + Sync + 'static,

Build the fan and START it. Threads are spawned HERE, at boot — never on the request path. That is the entire point of the type.

Source

pub fn start_with_arena<A, M, F>( class: OpClass, workers: usize, depth: usize, make: M, run: F, ) -> Pipeline<T>
where A: Send + 'static, M: Fn(usize) -> A + Send + Sync + 'static, F: Fn(&mut A, T) + Send + Sync + 'static,

The same fan, but each worker owns an ARENA built once at boot.

This is the half of “zero initialisation” the plain start does not give you. A standing fan removes the thread spawn; it does not remove the buffer. If the work still does Vec::with_capacity per operation, the kernel still zeroes fresh pages for it — which is kernel_init_pages, 4.7% of the top profile on a linux.git clone, the single largest kernel cost measured there.

make runs once per worker, at boot. run receives &mut A, so the buffer that was grown for the first operation is still there, at capacity, for the ten-thousandth. The caller is responsible for clear()-ing rather than reallocating — clear keeps capacity, which is the whole point, and is why this takes &mut A instead of handing back an owned buffer per call.

Source

pub fn submit(&self, item: T) -> Result<usize, SubmitError>

Hand an operation to the standing fan. Allocates nothing but the queue slot; spawns nothing.

Source

pub fn class(&self) -> OpClass

The class this fan serves.

Source

pub fn served(&self) -> u64

Operations a worker has actually picked up.

Source

pub fn queued(&self) -> usize

Items waiting for a worker.

Source

pub fn workers(&self) -> usize

Threads standing in this fan.

Source

pub fn shutdown(&self)

Stop accepting work, drain what is queued, and JOIN every worker.

Joining rather than detaching: a worker that outlives the pipeline holds an Arc on the queue and on whatever the closure captured, which on a server means a repository handle that never closes.

Trait Implementations§

Source§

impl<T: Send + 'static> Drop for Pipeline<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Pipeline<T>

§

impl<T> RefUnwindSafe for Pipeline<T>
where Arc<Queue<T>>: RefUnwindSafe,

§

impl<T> Send for Pipeline<T>
where Arc<Queue<T>>: Send,

§

impl<T> Sync for Pipeline<T>
where Arc<Queue<T>>: Sync,

§

impl<T> Unpin for Pipeline<T>
where Arc<Queue<T>>: Unpin,

§

impl<T> UnsafeUnpin for Pipeline<T>
where Arc<Queue<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Pipeline<T>
where Arc<Queue<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more