Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ and listed with their assets on the
"of it builds …", and the overview lists *Builds* below the groups: the
build servers stay after a build so the next one is fast, and were in the
lane's number but in no group.
- **A lane's need for the pool names its builds** (ADR-0119). The lease
step says "… memory (of it builds …)" and `remote_lane_need` in
`daemon.log` logs `builds`: the most the lane's build job took, as its
daemon measured it (a node asks each lane's daemon). Placement still takes
the whole memory; a node before this release sends no part.
- **main is stopped when only what serves its lanes runs** (ADR-0119). A
`singleton` the stop of main keeps for running lanes no longer shows main
as running with a Stop button; the stop says what keeps running, and for
Expand Down
1 change: 1 addition & 0 deletions crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ fn lane_estimate(
let need = devstack_node::share::Need {
cpus: e.cpus.max(CPUS),
memory: if runs { e.memory.max(MEMORY) } else { MEMORY },
builds: if runs { e.builds } else { 0 },
disk_repo: e.disk_repo,
disk_lane: if counted { e.disk_lane } else { DISK },
gpus: None,
Expand Down
16 changes: 13 additions & 3 deletions crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ pub fn floor_of(n: &devstack_config::model::Need) -> Option<devstack_node::share
Some(devstack_node::share::Need {
cpus: n.cpus.unwrap_or(0.0),
memory: n.memory.unwrap_or(0),
builds: 0,
disk_repo: 0,
disk_lane: n.disk.unwrap_or(0),
gpus: n.gpus.as_ref().map(|g| devstack_node::share::GpuNeed {
Expand Down Expand Up @@ -870,13 +871,22 @@ impl RemoteLane {
crate::diag::info(
"remote_lane_need",
serde_json::json!({ "lane": spec.name, "node": offer.node.name,
"cpus": n.cpus, "memory": n.memory, "disk_repo": n.disk_repo,
"disk_lane": n.disk_lane, "from": from }),
"cpus": n.cpus, "memory": n.memory, "builds": n.builds,
"disk_repo": n.disk_repo, "disk_lane": n.disk_lane, "from": from }),
);
// The builds' part of the memory (ADR-0119 point 3), when known.
let builds = if n.builds > 0 {
format!(
" (of it builds {})",
devstack_node::coordinator::gib(n.builds)
)
} else {
String::new()
};
(spec.step)(
1,
&format!(
"lease on {}: {:.1} CPU, {} memory, {} disk ({from})",
"lease on {}: {:.1} CPU, {} memory{builds}, {} disk ({from})",
offer.node.name,
n.cpus,
devstack_node::coordinator::gib(n.memory),
Expand Down
4 changes: 4 additions & 0 deletions crates/devstack-daemon/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ pub struct Estimate {
pub cpus: f64,
/// Bytes: each one's highest over the last ten minutes, summed.
pub memory: u64,
/// Bytes: of `memory`, the build job's highest (ADR-0119 point 3).
pub builds: u64,
/// Bytes: the tree without `.git` and its state (its sources,
/// dependencies and builds), its snapshot, artifacts and logs, and its
/// Compose volumes.
Expand Down Expand Up @@ -508,10 +510,12 @@ impl Sampler {
.filter(|(k, _)| *k != GPU_KEY)
.map(|(_, s)| s.peak())
.fold((0.0, 0), |(c, m), (pc, pm)| (c + pc, m + pm));
let builds = inner.series.get("build").map_or(0, |s| s.peak().1);
let d = &inner.disk;
Estimate {
cpus,
memory,
builds,
disk_lane: tree + d.snapshot + d.artifacts + d.logs + d.volumes.unwrap_or(0),
disk_repo: images,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/devstack-node/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4435,7 +4435,7 @@ mod placement_tests {
memory: GIB,
disk_repo: 20 * GIB,
disk_lane: 10 * GIB,
gpus: None,
..Need::default()
};
// 30 GiB room: enough for a node with the repository's images
// (10 + 5 free), not for a cold one (30 + 5).
Expand Down
102 changes: 102 additions & 0 deletions crates/devstack-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3319,6 +3319,46 @@ async fn shared_tunnel(
}
}

/// What the lane's build job takes of its memory now, as its daemon
/// measures it (`builds` of `/v1/usage`, ADR-0119 point 3): the node sees
/// the lane as one container and cannot tell its builds apart. `None` when
/// the daemon does not answer within a few seconds.
async fn lane_builds(d: &DaemonAddr) -> Option<u64> {
use http_body_util::BodyExt;
let ask = async {
let tcp = tokio::net::TcpStream::connect(&d.addr).await.ok()?;
let (mut send, conn) =
hyper::client::conn::http1::handshake(hyper_util::rt::TokioIo::new(tcp))
.await
.ok()?;
tokio::spawn(conn);
let req = hyper::Request::builder()
.uri("/v1/usage")
.header(hyper::header::HOST, d.host())
.header(hyper::header::AUTHORIZATION, format!("Bearer {}", d.token))
.body(http_body_util::Empty::<hyper::body::Bytes>::new())
.ok()?;
let res = send.send_request(req).await.ok()?;
if !res.status().is_success() {
return None;
}
let body = res.into_body().collect().await.ok()?.to_bytes();
builds_of(&body)
};
tokio::time::timeout(Duration::from_secs(3), ask)
.await
.ok()
.flatten()
}

/// `builds.memory` of a daemon's usage report.
fn builds_of(report: &[u8]) -> Option<u64> {
serde_json::from_slice::<serde_json::Value>(report)
.ok()?
.pointer("/builds/memory")?
.as_u64()
}

/// Pass `req` to the lane's daemon at `path`, with its token; a tunnel is
/// spliced once the daemon switched protocols.
async fn pass(
Expand Down Expand Up @@ -3891,13 +3931,35 @@ async fn background(s: Shared) {
let all: Vec<&crate::policy::NodePolicy> = policies.iter().collect();
crate::policy::NodePolicy::strictest(&all).and_then(|p| p.share_percent)
};
// Of that, each lane's builds, as its daemon measures them.
let daemons: Vec<(String, DaemonAddr)> = s
.daemons
.lock()
.unwrap()
.iter()
.filter(|(id, _)| by.contains_key(*id))
.map(|(id, d)| (id.clone(), d.clone()))
.collect();
let mut asking = tokio::task::JoinSet::new();
for (id, d) in daemons {
asking.spawn(async move { (id, lane_builds(&d).await) });
}
let mut builds = Vec::new();
while let Some(r) = asking.join_next().await {
if let Ok((id, Some(b))) = r {
builds.push((id, b));
}
}
{
// Half of the most this node offers its lanes (ADR-0066).
let cap = s.share.most_cpus(cores as f64, percent) / 2.0;
let mut runs = s.runs.lock().unwrap();
for (id, a) in &by {
runs.load(id, *a, cap);
}
for (id, b) in &builds {
runs.builds(id, *b);
}
}
let used = by.values().fold(Amount::default(), |a, b| Amount {
cpus: a.cpus + b.cpus,
Expand Down Expand Up @@ -4415,6 +4477,46 @@ pub fn serve_blocking(config: NodeConfig, listen: std::net::SocketAddr) -> Resul
mod tests {
use super::*;

#[tokio::test]
async fn a_lanes_builds_come_from_its_daemon_with_its_token_and_host() {
// A daemon that answers its token at its loopback host only, as one does.
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap().to_string();
let port = listener.local_addr().unwrap().port();
let app = axum::Router::new().route(
"/v1/usage",
get(move |h: hyper::HeaderMap| async move {
let ok = h.get("authorization").is_some_and(|v| v == "Bearer t0k")
&& h.get("host")
.is_some_and(|v| *v == *format!("127.0.0.1:{port}"));
if ok {
(
StatusCode::OK,
r#"{"builds":{"name":"builds","cpu":0.0,"memory":5368709120}}"#,
)
} else {
(StatusCode::UNAUTHORIZED, "{}")
}
}),
);
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
let d = |token: &str| DaemonAddr {
addr: addr.clone(),
token: token.into(),
infra_ports: Vec::new(),
infra_udp_ports: Vec::new(),
};
assert_eq!(lane_builds(&d("t0k")).await, Some(5 << 30));
assert_eq!(lane_builds(&d("wrong")).await, None);
// Nobody listens: none, soon.
let gone = DaemonAddr {
addr: "127.0.0.1:1".into(),
..d("t0k")
};
assert_eq!(lane_builds(&gone).await, None);
assert_eq!(builds_of(br#"{"services":[]}"#), None);
}

#[test]
fn a_gone_lanes_projects_are_found_by_slot_and_place() {
let gone = "d4713a1a05c412cb60a5755a";
Expand Down
1 change: 1 addition & 0 deletions crates/devstack-node/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
pub const MIN_NEED: Need = Need {
cpus: 0.25,
memory: 256 << 20,
builds: 0,
disk_repo: 0,
disk_lane: 0,
gpus: None,
Expand Down
32 changes: 32 additions & 0 deletions crates/devstack-node/src/runs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ impl Runs {
}
}

/// What its build job takes of its memory now, as its daemon says
/// (ADR-0119 point 3): part of what [`Runs::load`] measured.
pub fn builds(&mut self, id: &str, bytes: u64) {
if let Some(s) = self.by.get_mut(id) {
s.peak.builds = s.peak.builds.max(bytes);
}
}

/// What its slot and its containers' images take now.
pub fn disk(&mut self, id: &str, lane: u64, images: u64) {
let Some(s) = self.by.get_mut(id) else {
Expand Down Expand Up @@ -388,6 +396,30 @@ mod tests {
assert!(r.report().is_empty());
}

#[test]
fn a_runs_builds_are_its_highest_as_its_daemon_said() {
let mut r = Runs::default();
r.begin("l1", "shop");
r.load(
"l1",
Amount {
cpus: 1.0,
memory: 9 * GIB,
},
12.0,
);
r.builds("l1", 5 * GIB);
r.builds("l1", 2 * GIB);
r.builds("gone", GIB);
r.by.get_mut("l1").unwrap().since = Instant::now().checked_sub(COUNTS_AFTER);
let p = r.report()[0].peak;
assert_eq!(
(p.memory, p.builds),
(9 * GIB, 5 * GIB),
"a part, not added"
);
}

#[test]
fn steady_use_counts_from_up_its_95th_percentile() {
let mut r = Runs::default();
Expand Down
32 changes: 31 additions & 1 deletion crates/devstack-node/src/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub struct Amount {
pub struct Need {
pub cpus: f64,
pub memory: u64,
/// Of `memory`, the most its build job took (compilers and the build
/// servers that stay warm after a build, ADR-0119 point 3): said, so a
/// need can be explained; never added, `memory` holds it already. Absent
/// from an older peer.
#[serde(default, skip_serializing_if = "is_zero")]
pub builds: u64,
/// The repository's part of its disk: the lane image and the
/// infrastructure's images, shared by the repository's lanes on a node.
#[serde(default, skip_serializing_if = "is_zero")]
Expand Down Expand Up @@ -87,6 +93,7 @@ impl Need {
Need {
cpus: self.cpus.max(o.cpus),
memory: self.memory.max(o.memory),
builds: self.builds.max(o.builds),
disk_repo: self.disk_repo.max(o.disk_repo),
disk_lane: self.disk_lane.max(o.disk_lane),
gpus: match (self.gpus, o.gpus) {
Expand Down Expand Up @@ -507,14 +514,37 @@ mod tests {
assert_eq!(idle_cpus((100, 1000), (150, 1100), 8), 4.0);
}

#[test]
fn a_needs_builds_are_said_apart_and_an_older_peer_reads_without_them() {
let n = Need {
cpus: 1.0,
memory: 9 * GIB,
builds: 5 * GIB,
..Need::default()
};
let wire = serde_json::to_value(n).unwrap();
assert_eq!(wire["builds"], 5 * GIB);
// What an older peer sends has none; what it reads keeps its memory.
let old: Need = serde_json::from_str(r#"{"cpus":1.0,"memory":1024}"#).unwrap();
assert_eq!((old.memory, old.builds), (1024, 0));
let amount: Amount = serde_json::from_value(wire).unwrap();
assert_eq!(amount.memory, 9 * GIB);
assert!(
!serde_json::to_string(&Need::default())
.unwrap()
.contains("builds")
);
assert_eq!(old.max(n).builds, 5 * GIB);
}

#[test]
fn a_floor_raises_each_part_and_the_disk_in_all() {
let measured = Need {
cpus: 1.0,
memory: 2 * GIB,
disk_repo: 6 * GIB,
disk_lane: 3 * GIB,
gpus: None,
..Need::default()
};
let (same, raised) = measured.at_least(Need {
memory: GIB,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ADR-0119: A lane's memory counts what it owns and names its builds; main is stopped when only what serves its lanes runs

- **Status:** Accepted (card in the pull request); points 1, 2 and 4 built, point 3 follows
- **Status:** Accepted (card in the pull request); built (points 1, 2 and 4 in #626, point 3 in its own pull request)
- **Date:** 2026-11-24
- **Deciders:** project owner
- **Related:** [ADR-0009](0009-the-daemon-owns-every-process-tree.md) (process trees), [ADR-0020](0020-builds-share-one-long-lived-build-job.md) (the build job, its servers stay warm), [ADR-0049](0049-a-lanes-need-is-measured-disk-included.md) (a lane's need), [ADR-0080](0080-the-main-tree-answers-as-a-lane-shared-is-deprecated.md) (`singleton`), [ADR-0095](0095-the-daemon-ends-with-the-last-tree.md) (main stops alone), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md)
Expand Down Expand Up @@ -59,6 +59,18 @@ As built (points 1, 2 and 4):
`containers` and `lanes` of the daemon's `200`; the stack page's
"main stopped" names what keeps running.

As built (point 3, a pull request of its own after #626):

4. **The need's builds.** `Need::builds` in `crates/devstack-node/src/share.rs`
(left out at zero, so an older peer reads the rest; `max` keeps the
larger). The daemon's estimate from the main tree takes the build
series' peak (`Estimate::builds`); a node asks each lane's daemon for
`builds` of `/v1/usage` every round, all at once with three seconds each
(`lane_builds`), and keeps the most in the run (`Runs::builds`), whence
the coordinator's footprint keeps the most of the last five. The lease
step says "of it builds …" and `remote_lane_need` logs `builds`.
Placement is unchanged: it takes `memory`.

## Consequences

- The memory devstack shows falls for every stack with several processes
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ stay.
| [0116](0116-admins-see-a-machine-that-asks-to-run-lanes.md) | Admins see a machine that asks to run lanes, and are told when one starts | Accepted (card in the pull request); built |
| [0117](0117-the-dashboard-pushes-a-branch-that-is-ahead-of-its-upstream.md) | The dashboard pushes a branch that is ahead of its upstream, and the start page shows how far each stack is | Accepted (card in the pull request); built |
| [0118](0118-lane-list-says-which-lanes-are-done.md) | `lane list` says which lanes are done, and devstack removes none of them | Accepted (card in the pull request); built; amended 2026-11-23 (`new`, no command for a name a shell reads) |
| [0119](0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md) | A lane's memory counts what it owns and names its builds; main is stopped when only what serves its lanes runs | Accepted (card in the pull request); points 1, 2, 4 built, point 3 follows |
| [0119](0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md) | A lane's memory counts what it owns and names its builds; main is stopped when only what serves its lanes runs | Accepted (card in the pull request); built |
7 changes: 6 additions & 1 deletion docs/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,12 @@ containers each took over the last ten minutes, and as disk its tree
and its Compose images; with nothing running, 0.5 CPU, 1 GiB and 10 GiB of
disk. `[lanes.need]` and the profile's `need` in the stack file raise each
part to what they say. The lease says the need and where it came from, in
the lane's start and in `daemon.log` (`remote_lane_need`).
the lane's start and in `daemon.log` (`remote_lane_need`). Of its memory it
names the builds' part (`builds`, [ADR-0119](adr/0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md)):
the compilers and the build servers that stay warm after a build, the most
of them the lane's daemon measured (a node asks it, since it sees the lane as
one container). The part is said, not added, and a node before 0.54.0 sends
none.

The need is a peak, its build included, and decides only whether a start
fits the room free now: running lanes count by what they use. Besides it a
Expand Down
Loading