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

A factory that can be used to configure and create a LocalExecutor.

Methods can be chained on it in order to configure it.

The spawn method will take ownership of the builder and create a Result to the LocalExecutor handle with the given configuration.

The LocalExecutor::default free function uses a Builder with default configuration and unwraps its return value.

You may want to use LocalExecutorBuilder::spawn instead of LocalExecutor::default, when you want to recover from a failure to launch a thread. The LocalExecutor::default function will panic where the Builder method will return a io::Result.

§Examples

use glommio::LocalExecutorBuilder;

let builder = LocalExecutorBuilder::default();
let ex = builder.make().unwrap();

Implementations§

source§

impl LocalExecutorBuilder

source

pub fn new(placement: Placement) -> LocalExecutorBuilder

Generates the base configuration for spawning a LocalExecutor, from which configuration methods can be chained. The method’s only argument is the Placement policy by which the LocalExecutor is 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) -> LocalExecutorBuilder

Spin for duration before parking a reactor

source

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

Names the thread-to-be. Currently, the name is used for identification only in panic messages.

source

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

Amount of memory to reserve for storage I/O. This will be preallocated and registered with io_uring. It is still possible to use more than that, but it will come from the standard allocator and performance will suffer.

The system will always try to allocate at least 64 kiB for I/O memory, and the default is 10 MiB.

source

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

The depth of the IO rings to create. This influences the level of IO concurrency. A higher ring depth allows a shard to submit a greater number of IO requests to the kernel at once.

Values above zero are valid and the default is 128.

source

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

How often need_preempt will return true by default.

Lower values mean task queues will switch execution more often, which can help latency but harm throughput. When individual task queues are present, this value can still be dynamically lowered through the Latency setting.

Default is 100ms.

source

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

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 ) -> LocalExecutorBuilder

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: Option<Box<dyn StallDetectionHandler + 'static>> ) -> Self

Whether to detect stalls in unyielding tasks. stall::DefaultStallDetectionHandler installs a signal handler for nix::libc::SIGUSR1, so is disabled by default.

§Examples
use glommio::{DefaultStallDetectionHandler, LocalExecutorBuilder};

let local_ex = LocalExecutorBuilder::default()
    .detect_stalls(Some(Box::new(DefaultStallDetectionHandler {})))
    .make()
    .unwrap();
source

pub fn make(self) -> Result<LocalExecutor, ()>

Make a new LocalExecutor by taking ownership of the Builder, and returns a Result to the executor.

§Examples
use glommio::LocalExecutorBuilder;

let local_ex = LocalExecutorBuilder::default().make().unwrap();
source

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

Spawn a new LocalExecutor in a new thread with a given task.

This spawn function is an ergonomic shortcut for calling std::thread::spawn, LocalExecutorBuilder::make in the spawned thread, and then LocalExecutor::run. This spawn function takes ownership of a LocalExecutorBuilder with the configuration for the LocalExecutor, spawns that executor in a new thread, and starts the task given by fut_gen() in that thread.

The indirection of fut_gen() here (instead of taking a Future) allows for futures that may not be Send-able once started. As this executor is thread-local it can guarantee that the futures will not be Sent once started.

§Panics

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

§Example
use glommio::LocalExecutorBuilder;

let handle = LocalExecutorBuilder::default()
    .spawn(|| async move {
        println!("hello");
    })
    .unwrap();

handle.join().unwrap();

Trait Implementations§

source§

impl Debug for LocalExecutorBuilder

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for LocalExecutorBuilder

source§

fn default() -> Self

Returns the “default value” for a type. 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