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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Runtime ownership of the readiness driver and explicit blocking workers.
use crate::{Result, RuntimeConfig, blocking::pool::Pool, readiness::Reactor};
/// Bounded I/O and delegated-work activity for operator diagnostics.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ServiceSnapshot {
/// Outstanding readiness waits, including not-yet-installed registrations.
pub(crate) readiness_waits: usize,
/// Configured readiness wait limit.
pub(crate) readiness_capacity: usize,
/// Registrations currently retained by zio.
pub(crate) readiness_registered: usize,
/// Whether the readiness driver failed and rejected further waits.
pub(crate) readiness_failed: bool,
/// First terminal backend failure, when present.
pub(crate) readiness_error: Option<String>,
/// Native jobs waiting for a worker.
pub(crate) blocking_queued: usize,
/// Native jobs already executing; these cannot be forcibly cancelled.
pub(crate) blocking_running: usize,
/// Completed results retained natively until caller commit or abandonment.
pub(crate) blocking_completed: usize,
/// Queued captures or abandoned results being destroyed on native workers.
pub(crate) blocking_discarding: usize,
/// Maximum queued, running, completed, and discarding native jobs combined.
pub(crate) blocking_capacity: usize,
/// Native body or late-result/queued-capture destructor panics observed by workers.
pub(crate) blocking_panics: u64,
/// A native worker failed outside its ordinary job boundary; admission is closed.
pub(crate) blocking_failed: bool,
}
pub(crate) struct Services {
pub(crate) reactor: Reactor,
pub(crate) blocking: Pool,
}
impl Services {
pub(crate) fn new(
config: RuntimeConfig,
owner: std::sync::Weak<crate::control::Shared>,
) -> Result<Self> {
Ok(Self {
reactor: Reactor::new(config.io_capacity(), owner.clone())?,
blocking: Pool::new(config.blocking_threads(), config.blocking_capacity(), owner)?,
})
}
pub(crate) fn stop(&self) {
self.blocking.stop();
self.reactor.stop();
}
pub(crate) fn join(&self) {
self.reactor.join();
self.blocking.join();
}
pub(crate) fn snapshot(&self) -> ServiceSnapshot {
let mut snapshot = ServiceSnapshot::default();
self.reactor.snapshot(&mut snapshot);
self.blocking.snapshot(&mut snapshot);
snapshot
}
}
impl Drop for Services {
fn drop(&mut self) {
self.stop();
self.join();
}
}
#[cfg(test)]
#[path = "services_test.rs"]
mod services_test;
impl ServiceSnapshot {
/// Outstanding readiness waits, including not-yet-installed registrations.
pub fn readiness_waits(&self) -> usize {
self.readiness_waits
}
/// Configured readiness wait limit.
pub fn readiness_capacity(&self) -> usize {
self.readiness_capacity
}
/// Registrations currently retained by zio.
pub fn readiness_registered(&self) -> usize {
self.readiness_registered
}
/// Whether the readiness driver failed and rejected further waits.
pub fn readiness_failed(&self) -> bool {
self.readiness_failed
}
/// First terminal backend failure, when present.
pub fn readiness_error(&self) -> Option<&str> {
self.readiness_error.as_deref()
}
/// Native jobs waiting for a worker.
pub fn blocking_queued(&self) -> usize {
self.blocking_queued
}
/// Native jobs already executing; these cannot be forcibly cancelled.
pub fn blocking_running(&self) -> usize {
self.blocking_running
}
/// Completed results retained natively until caller commit or abandonment.
pub fn blocking_completed(&self) -> usize {
self.blocking_completed
}
/// Queued captures or abandoned results being destroyed on native workers.
pub fn blocking_discarding(&self) -> usize {
self.blocking_discarding
}
/// Maximum queued, running, completed, and discarding native jobs combined.
pub fn blocking_capacity(&self) -> usize {
self.blocking_capacity
}
/// Native body or late-result/queued-capture destructor panics observed by workers.
pub fn blocking_panics(&self) -> u64 {
self.blocking_panics
}
/// A native worker failed outside its ordinary job boundary; admission is closed.
pub fn blocking_failed(&self) -> bool {
self.blocking_failed
}
}