Skip to main content

schedr_model/
usage.rs

1//! What a schedr process uses (decision 463): its memory and CPU and its container's, and a
2//! worker's memory by part. Reported by masters (their row), workers (their heartbeat) and the
3//! webserver (its `/deployment` answer).
4
5use serde::{Deserialize, Serialize};
6
7/// A schedr process's memory and CPU, and its container's.
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct NodeUsage {
10    /// Resident memory, in bytes.
11    pub resident_bytes: u64,
12    /// CPU time used (user and system) since it started, in seconds.
13    pub cpu_seconds: f64,
14    /// Its cgroup's memory now (`memory.current`); none outside a cgroup v2.
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    pub container_bytes: Option<u64>,
17    /// The smallest `memory.max` on the way up from its cgroup; none when unlimited.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub container_limit_bytes: Option<u64>,
20}
21
22/// A worker's memory by part: the agent's own process, then what it started.
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub struct WorkerUsage {
25    /// The agent's process (in standalone also the master's and the webserver's).
26    pub process: NodeUsage,
27    /// Its fork servers', together.
28    pub fork_servers_bytes: u64,
29    /// Its wait step hosts', together.
30    pub watcher_hosts_bytes: u64,
31    /// Its running tasks', together, as their memory watchdog last measured them.
32    pub tasks_bytes: u64,
33    /// The largest of them, largest first.
34    #[serde(default)]
35    pub largest_tasks: Vec<TaskMemory>,
36}
37
38/// A running task's memory, named.
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct TaskMemory {
41    /// The attempt.
42    pub attempt_id: String,
43    /// Its DAG.
44    pub dag_id: String,
45    /// Its run.
46    pub run_id: String,
47    /// Its task.
48    pub task_id: String,
49    /// Its map index; none for an unmapped task.
50    #[serde(default, skip_serializing_if = "Option::is_none")]
51    pub map_index: Option<u32>,
52    /// Its memory, in bytes.
53    pub bytes: u64,
54}
55
56/// A worker's memory by part, without its process's own figures: what a sample keeps of it
57/// (decision 464).
58#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub struct WorkerParts {
60    /// Its fork servers', together.
61    pub fork_servers_bytes: u64,
62    /// Its wait step hosts', together.
63    pub watcher_hosts_bytes: u64,
64    /// Its running tasks', together.
65    pub tasks_bytes: u64,
66    /// The largest of them, largest first.
67    #[serde(default)]
68    pub largest_tasks: Vec<TaskMemory>,
69}
70
71impl WorkerUsage {
72    /// Its parts, its process's figures left out.
73    #[must_use]
74    pub fn parts(&self) -> WorkerParts {
75        WorkerParts {
76            fork_servers_bytes: self.fork_servers_bytes,
77            watcher_hosts_bytes: self.watcher_hosts_bytes,
78            tasks_bytes: self.tasks_bytes,
79            largest_tasks: self.largest_tasks.clone(),
80        }
81    }
82}