Pipeline workers follow the CPU; one pad that never disconnects

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 15:43:53 -06:00
1 parent 2d12b19052
commit ffdde86ef6
2 files changed
+116 -9

No files matched your search

+27 -2
View File
@@ -292,12 +292,28 @@ fn next() -> Arc<Pending> {
}
}
/// Starts the workers (half the logical processors, 2 to 8) on first use.
/// How many workers make pipelines: `asked` (`VICTORY_PIPELINE_WORKERS`, 1 to
/// 64), else two thirds of the logical processors, 2 to 16. They run below the
/// title's own threads, and a cold cache queues hundreds at once.
fn worker_count(asked: Option<usize>, processors: usize) -> usize {
match asked {
Some(n) => n.clamp(1, 64),
None => (processors * 2 / 3).clamp(2, 16),
}
}
/// Starts the workers ([`worker_count`]) on first use.
fn workers() -> bool {
static RUNNING: OnceLock<bool> = OnceLock::new();
*RUNNING.get_or_init(|| {
let mut running = false;
let workers = std::thread::available_parallelism().map_or(2, |n| (n.get() / 2).clamp(2, 8));
let workers = worker_count(
std::env::var("VICTORY_PIPELINE_WORKERS")
.ok()
.and_then(|v| v.trim().parse().ok()),
std::thread::available_parallelism().map_or(2, |n| n.get()),
);
tracing::info!(workers, "pipeline workers");
for i in 0..workers {
let spawned = std::thread::Builder::new()
.name(format!("victory-pipelines-{i}"))
@@ -349,6 +365,15 @@ fn drained() {
mod tests {
use super::*;
#[test]
fn worker_count_follows_the_processors_and_the_switch() {
assert_eq!(worker_count(None, 1), 2);
assert_eq!(worker_count(None, 24), 16);
assert_eq!(worker_count(None, 64), 16);
assert_eq!(worker_count(Some(0), 24), 1);
assert_eq!(worker_count(Some(20), 24), 20);
}
/// A first use queues the pipeline and, within the budget, gets the
/// worker's answer (here: no host pipeline for no shaders).
#[test]