pub struct LocalExecutorPoolBuilder { /* private fields */ }
Expand description

A factory to configure and create a pool of LocalExecutors.

Configuration methods apply their settings to all LocalExecutors in the pool unless otherwise specified. Methods can be chained on the builder in order to configure it. The Self::on_all_shards method will take ownership of the builder and create a PoolThreadHandles struct which can be used to join the executor threads.

§Example

use glommio::{LocalExecutorPoolBuilder, PoolPlacement};

let handles = LocalExecutorPoolBuilder::new(PoolPlacement::Unbound(4))
    .on_all_shards(|| async move {
        let id = glommio::executor().id();
        println!("hello from executor {id}");
    })
    .unwrap();

handles.join_all();

Implementations§

source§

impl LocalExecutorPoolBuilder

source

pub fn new(placement: PoolPlacement) -> Self

Generates the base configuration for spawning a pool of LocalExecutors, from which configuration methods can be chained. The method’s only argument is the PoolPlacement policy by which LocalExecutors are bound to the machine’s hardware topology. i.e. how many and which CPUs to use.

source

pub fn spin_before_park(self, spin: Duration) -> Self

Please see documentation under LocalExecutorBuilder::spin_before_park for details. The setting is applied to all executors in the pool.

source

pub fn name(self, name: &str) -> Self

Please see documentation under LocalExecutorBuilder::name for details. The setting is applied to all executors in the pool. Note that when a thread is spawned, the name is combined with a hyphen and numeric id (e.g. myname-1) such that each thread has a unique name.

source

pub fn io_memory(self, io_memory: usize) -> Self

Please see documentation under LocalExecutorBuilder::io_memory for details. The setting is applied to all executors in the pool.

source

pub fn ring_depth(self, ring_depth: usize) -> Self

Please see documentation under LocalExecutorBuilder::ring_depth for details. The setting is applied to all executors in the pool.

source

pub fn preempt_timer(self, dur: Duration) -> Self

Please see documentation under LocalExecutorBuilder::preempt_timer for details. The setting is applied to all executors in the pool.

source

pub fn record_io_latencies(self, enabled: bool) -> Self

Whether to record the latencies of individual IO requests as part of the IO stats. Recording latency can be expensive. Disabled by default.

source

pub fn blocking_thread_pool_placement(self, placement: PoolPlacement) -> Self

The placement policy of the blocking thread pool. Defaults to one thread using the same placement strategy as the host executor.

source

pub fn detect_stalls( self, handler_gen: Option<Box<dyn Fn() -> Box<dyn StallDetectionHandler + 'static>>> ) -> Self

Whether to detect stalls in unyielding tasks. This method takes a closure of handler_gen, which will be called on each new thread to generate the stall detection handler to be used in that executor. stall::DefaultStallDetectionHandler installs a signal handler for nix::libc::SIGUSR1, so is disabled by default.

§Examples
use glommio::{
    timer::Timer,
    DefaultStallDetectionHandler,
    LocalExecutorPoolBuilder,
    PoolPlacement,
};

let local_ex = LocalExecutorPoolBuilder::new(PoolPlacement::Unbound(4))
    .detect_stalls(Some(Box::new(|| Box::new(DefaultStallDetectionHandler {}))))
    .on_all_shards(move || async {
        Timer::new(std::time::Duration::from_millis(100)).await;
        println!("Hello world!");
    })
    .expect("failed to spawn local executors")
    .join_all();
source

pub fn on_all_shards<G, F, T>( self, fut_gen: G ) -> Result<PoolThreadHandles<T>, ()>
where G: FnOnce() -> F + Clone + Send + 'static, F: Future<Output = T> + 'static, T: Send + 'static,

Spawn a pool of LocalExecutors in a new thread according to the PoolPlacement policy, which is Unbound by default.

This method is the pool equivalent of LocalExecutorBuilder::spawn.

The method takes a closure fut_gen which will be called on each new thread to obtain the Future to be executed there.

§Panics

The newly spawned thread panics if creating the executor fails. If you need more fine-grained error handling consider initializing those entities manually.

Trait Implementations§

source§

impl Debug for LocalExecutorPoolBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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