1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Builder-supplied scheduler configuration for the embedded runtime.
use std::time::Duration;
/// Configuration used when constructing the embedded BEAM runtime.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct RuntimeConfig {
/// Optional scheduler thread count supplied by the engine builder.
///
/// `None` is passed through to beamr so the embedded runtime applies its own
/// runtime-aware default.
pub thread_count: Option<usize>,
/// Bounded readiness and retry policy for live signal mailbox delivery.
pub signal_delivery: SignalDeliveryConfig,
}
/// Bounded signal delivery retry policy supplied by engine configuration.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SignalDeliveryConfig {
/// Maximum time to wait for a just-spawned process body to materialize.
pub ready_timeout: Duration,
/// Maximum number of mailbox enqueue attempts after the ready gate.
pub max_enqueue_attempts: u32,
/// Initial sleep between failed enqueue attempts.
pub initial_backoff: Duration,
/// Upper bound for exponential backoff between enqueue attempts.
pub max_backoff: Duration,
}
impl Default for SignalDeliveryConfig {
fn default() -> Self {
Self::new(
Duration::from_millis(50),
8,
Duration::from_millis(1),
Duration::from_millis(8),
)
}
}
impl SignalDeliveryConfig {
/// Create an explicit signal delivery policy.
#[must_use]
pub const fn new(
ready_timeout: Duration,
max_enqueue_attempts: u32,
initial_backoff: Duration,
max_backoff: Duration,
) -> Self {
Self {
ready_timeout,
max_enqueue_attempts,
initial_backoff,
max_backoff,
}
}
}
impl RuntimeConfig {
/// Create runtime configuration from the builder-supplied scheduler count.
#[must_use]
pub fn new(thread_count: Option<usize>) -> Self {
Self {
thread_count,
signal_delivery: SignalDeliveryConfig::default(),
}
}
/// Override the signal delivery retry policy.
#[must_use]
pub const fn with_signal_delivery(mut self, signal_delivery: SignalDeliveryConfig) -> Self {
self.signal_delivery = signal_delivery;
self
}
}