use crate::platform::String;
const KILOBYTE: usize = 1024;
const MEGABYTE: usize = 1024 * KILOBYTE;
pub const SMALL_POOL_SIZE: usize = 64 * KILOBYTE;
pub const MEDIUM_POOL_SIZE: usize = MEGABYTE;
pub const LARGE_POOL_SIZE: usize = 16 * MEGABYTE;
pub const DEFAULT_GLOBAL_QUEUE_CAPACITY: usize = 8192;
pub const DEFAULT_LOCAL_QUEUE_CAPACITY: usize = 256;
#[allow(clippy::module_name_repetitions)]
pub struct ExecutorConfig {
pub worker_threads: usize,
pub async_threads: usize,
pub max_global_queue_size: usize,
pub max_local_queue_size: usize,
pub thread_name_prefix: String,
#[cfg(feature = "numa")]
pub numa_aware: bool,
#[cfg(feature = "metrics")]
pub enable_metrics: bool,
pub preemption: PreemptionConfig,
pub memory: MemoryConfig,
pub cleanup: CleanupConfig,
}
impl Default for ExecutorConfig {
fn default() -> Self {
Self {
worker_threads: super::num_cpus(),
async_threads: (super::num_cpus() / 4).max(1),
max_global_queue_size: DEFAULT_GLOBAL_QUEUE_CAPACITY,
max_local_queue_size: DEFAULT_LOCAL_QUEUE_CAPACITY,
thread_name_prefix: "moirai-worker".into(),
#[cfg(feature = "numa")]
numa_aware: true,
#[cfg(feature = "metrics")]
enable_metrics: true,
preemption: PreemptionConfig::default(),
memory: MemoryConfig::default(),
cleanup: CleanupConfig::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct PreemptionConfig {
pub enabled: bool,
pub time_slice_us: u64,
pub priority_based: bool,
pub min_execution_time_us: u64,
}
impl Default for PreemptionConfig {
fn default() -> Self {
Self {
enabled: true,
time_slice_us: 10_000, priority_based: true,
min_execution_time_us: 1_000, }
}
}
#[derive(Debug, Clone)]
pub struct MemoryConfig {
pub use_memory_pools: bool,
pub small_pool_size: usize,
pub medium_pool_size: usize,
pub large_pool_size: usize,
pub track_per_task_memory: bool,
}
impl Default for MemoryConfig {
fn default() -> Self {
Self {
use_memory_pools: true,
small_pool_size: SMALL_POOL_SIZE,
medium_pool_size: MEDIUM_POOL_SIZE,
large_pool_size: LARGE_POOL_SIZE,
track_per_task_memory: cfg!(feature = "metrics"),
}
}
}
#[derive(Debug, Clone)]
pub struct CleanupConfig {
pub task_retention_duration: core::time::Duration,
pub cleanup_interval: core::time::Duration,
pub enable_automatic_cleanup: bool,
pub max_retained_tasks: usize,
}
impl Default for CleanupConfig {
fn default() -> Self {
Self {
task_retention_duration: core::time::Duration::from_mins(5),
cleanup_interval: core::time::Duration::from_secs(30), enable_automatic_cleanup: true,
max_retained_tasks: 10_000,
}
}
}