Struct glommio::LocalExecutorPoolBuilder
source · pub struct LocalExecutorPoolBuilder { /* private fields */ }
Expand description
A factory to configure and create a pool of LocalExecutor
s.
Configuration methods apply their settings to all LocalExecutor
s 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
impl LocalExecutorPoolBuilder
sourcepub fn new(placement: PoolPlacement) -> Self
pub fn new(placement: PoolPlacement) -> Self
Generates the base configuration for spawning a pool of
LocalExecutor
s, from which configuration methods can be chained.
The method’s only argument is the PoolPlacement
policy by which
LocalExecutor
s are bound to the machine’s hardware topology. i.e.
how many and which CPUs to use.
sourcepub fn spin_before_park(self, spin: Duration) -> Self
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.
sourcepub fn name(self, name: &str) -> Self
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.
sourcepub fn io_memory(self, io_memory: usize) -> Self
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.
sourcepub fn ring_depth(self, ring_depth: usize) -> Self
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.
sourcepub fn preempt_timer(self, dur: Duration) -> Self
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.
sourcepub fn record_io_latencies(self, enabled: bool) -> Self
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.
sourcepub fn blocking_thread_pool_placement(self, placement: PoolPlacement) -> Self
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.
sourcepub fn detect_stalls(
self,
handler_gen: Option<Box<dyn Fn() -> Box<dyn StallDetectionHandler + 'static>>>
) -> Self
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();
sourcepub fn on_all_shards<G, F, T>(
self,
fut_gen: G
) -> Result<PoolThreadHandles<T>, ()>
pub fn on_all_shards<G, F, T>( self, fut_gen: G ) -> Result<PoolThreadHandles<T>, ()>
Spawn a pool of LocalExecutor
s 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.