pub struct RuntimeConfig {
pub worker_threads: usize,
pub max_blocking_threads: usize,
pub thread_name: String,
pub thread_stack_size: Option<usize>,
pub thread_keep_alive: Duration,
pub shutdown_timeout: Duration,
pub blocking_lane_policies: BlockingLanePolicies,
pub enable_io: bool,
pub enable_time: bool,
}Expand description
Thread, driver and shutdown policy for one owned Tokio runtime.
Default uses the available CPU parallelism, falling back to four
workers. Self::for_parallelism derives a saturating, capped blocking
limit and aligns lane concurrency with it. Lanes share the global limit;
their individual maxima are not independent thread pools.
Validation performs no I/O or thread creation. Disabling a driver is a caller capability choice: networking needs I/O, while timers, scheduling and deadline-based waits need the time driver.
Fields§
§worker_threads: usizeNumber of asynchronous worker threads; must be positive.
max_blocking_threads: usizeManaged blocking capacity shared by the blocking lanes.
The Tokio blocking pool holds Self::tokio_blocking_threads threads:
this capacity plus headroom for blocking work outside the lanes.
thread_name: StringNonblank prefix used for runtime worker threads.
thread_stack_size: Option<usize>Optional stack size in bytes; None retains Tokio’s default.
thread_keep_alive: DurationIdle blocking-thread lifetime.
shutdown_timeout: DurationFallback budget for owner shutdown entrypoints called without a deadline.
A process that runs a ServiceLifecycle passes the lifecycle’s
deadline instead, so this budget applies only to owners shut down
without one. Calls that accept an explicit absolute deadline use that
deadline.
This is not a per-task execution timeout and cannot stop a blocking
closure already running on an operating-system thread.
blocking_lane_policies: BlockingLanePoliciesPer-lane admission, queueing and deadline policies.
enable_io: boolEnables Tokio’s I/O driver; enabled in the default profile.
enable_time: boolEnables Tokio’s timer driver; enabled in the default profile.
Implementations§
Source§impl RuntimeConfig
impl RuntimeConfig
Sourcepub fn for_parallelism(
thread_name: impl Into<String>,
available_parallelism: usize,
) -> Self
pub fn for_parallelism( thread_name: impl Into<String>, available_parallelism: usize, ) -> Self
Builds a validated entrypoint profile from the effective CPU quota.
available_parallelism should be the cgroup-aware value reported by
std::thread::available_parallelism. Keeping it explicit makes the
derivation deterministic in bootstrap tests and container profiles.
Sourcepub fn with_max_blocking_threads(
self,
limit: usize,
) -> Result<Self, RuntimeContractViolation>
pub fn with_max_blocking_threads( self, limit: usize, ) -> Result<Self, RuntimeContractViolation>
Applies an explicit global blocking limit and aligns every lane ceiling.
§Errors
Returns a contract violation when limit cannot reserve one slot for
each blocking lane or exceeds the supported process bound.
Sourcepub fn blocking_thread_headroom(&self) -> usize
pub fn blocking_thread_headroom(&self) -> usize
Tokio blocking threads beyond the managed capacity: one eighth of it, and at least two.
Direct spawn_blocking calls, DNS resolution and tokio::fs share the
Tokio pool with admitted lane work. Without headroom they could take the
threads that admitted work is counting on, and that work would queue
inside Tokio where admission cannot see it.
Sourcepub fn tokio_blocking_threads(&self) -> usize
pub fn tokio_blocking_threads(&self) -> usize
Size of the Tokio blocking pool: the managed capacity plus
Self::blocking_thread_headroom.
Sourcepub fn server_default(thread_name: impl Into<String>) -> Self
pub fn server_default(thread_name: impl Into<String>) -> Self
Creates the server default value.
Sourcepub fn broker_default() -> Self
pub fn broker_default() -> Self
Creates the broker default value.
Sourcepub fn namesrv_default() -> Self
pub fn namesrv_default() -> Self
Creates the namesrv default value.
Sourcepub fn proxy_default() -> Self
pub fn proxy_default() -> Self
Creates the proxy default value.
Sourcepub fn controller_default() -> Self
pub fn controller_default() -> Self
Creates the controller default value.