Skip to main content

RuntimeConfig

Struct RuntimeConfig 

Source
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: usize

Number of asynchronous worker threads; must be positive.

§max_blocking_threads: usize

Managed 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: String

Nonblank prefix used for runtime worker threads.

§thread_stack_size: Option<usize>

Optional stack size in bytes; None retains Tokio’s default.

§thread_keep_alive: Duration

Idle blocking-thread lifetime.

§shutdown_timeout: Duration

Fallback 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: BlockingLanePolicies

Per-lane admission, queueing and deadline policies.

§enable_io: bool

Enables Tokio’s I/O driver; enabled in the default profile.

§enable_time: bool

Enables Tokio’s timer driver; enabled in the default profile.

Implementations§

Source§

impl RuntimeConfig

Source

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.

Source

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.

Source

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.

Source

pub fn tokio_blocking_threads(&self) -> usize

Size of the Tokio blocking pool: the managed capacity plus Self::blocking_thread_headroom.

Source

pub fn server_default(thread_name: impl Into<String>) -> Self

Creates the server default value.

Source

pub fn broker_default() -> Self

Creates the broker default value.

Source

pub fn namesrv_default() -> Self

Creates the namesrv default value.

Source

pub fn proxy_default() -> Self

Creates the proxy default value.

Source

pub fn controller_default() -> Self

Creates the controller default value.

Source

pub fn validate(&self) -> Result<(), RuntimeContractViolation>

Validates this value.

§Errors

Returns a deterministic contract violation when a runtime setting is structurally invalid. It performs no I/O and never creates a runtime.

Trait Implementations§

Source§

impl Clone for RuntimeConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuntimeConfig

Source§

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

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

impl Default for RuntimeConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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