pub enum Placement {
Unbound,
Fenced(CpuSet),
Fixed(usize),
}
Expand description
Specifies a policy by which LocalExecutorBuilder
selects CPUs.
Placement
is used to bind LocalExecutor
s to a set of CPUs via
preconfigured policies designed to address a variety of use cases.
§Example
Some Placement
s allow manually filtering available CPUs via a
CpuSet
, such as MaxSpread
. The following would place shards on four
CPUs (a.k.a. hyper-threads) that are on NUMA node 0 and have an even
numbered package ID according to their CpuLocation
. The selection aims
to achieve a high degree of separation between the CPUs in terms of machine
topology. Each LocalExecutor
would be bound to a single CPU.
use glommio::{CpuSet, LocalExecutorBuilder, Placement};
let cpus = CpuSet::online()
.expect("Err: please file an issue with glommio")
.filter(|l| l.numa_node == 0)
.filter(|l| l.package % 2 == 0);
LocalExecutorBuilder::new(Placement::Fenced(cpus))
.spawn(|| async move {
// ... important stuff ...
})
.unwrap()
.join();
Variants§
Unbound
The Unbound
variant creates a LocalExecutor
s that are not bound to
any CPU.
Fenced(CpuSet)
The Fenced
variant binds the LocalExecutor
to the set
of CPUs specified by CpuSet
. With an unfiltered CPU
set returned by CpuSet::online
, this is similar to using Unbound
with the distinction that bringing additional CPUs online will not
allow the executor to run on the newly available CPUs.
§Errors
If the provided CpuSet
contains no CPUs, the builder will fail.
Fixed(usize)
The LocalExecutor
is bound to the CPU specified by
Fixed
.
§Errors
LocalExecutorBuilder
will return Result::Err
if the CPU doesn’t
exist.