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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! 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,
/// Whether the durable-outbox fan-out dispatch path is enabled.
pub outbox_enabled: bool,
}
/// 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,
}
}
/// Bound for draining the single cleanup worker after every registered
/// process has been force-unblocked.
///
/// A zero process-readiness bound is valid for refusal tests, but is not a
/// useful thread-shutdown observation window. Use at least the standard
/// readiness window and scale it by every job the worker can own (one
/// running plus the bounded queue) rather than imposing an unrelated
/// timeout constant.
pub(crate) fn cleanup_shutdown_timeout(self) -> Duration {
self.ready_timeout
.max(Self::default().ready_timeout)
.saturating_mul(self.max_enqueue_attempts.max(1).saturating_add(1))
}
}
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(),
outbox_enabled: false,
}
}
/// 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
}
/// Override whether the durable-outbox fan-out dispatch path is enabled.
#[must_use]
pub const fn with_outbox_enabled(mut self, enabled: bool) -> Self {
self.outbox_enabled = enabled;
self
}
}