Skip to content

Commit faad8bb

Browse files
authored
If all workers are fully allocated, shortcut find workers (TraceMachina#2130)
1 parent 342e478 commit faad8bb

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

nativelink-scheduler/src/api_worker_scheduler.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ impl ApiWorkerSchedulerImpl {
238238
platform_properties: &PlatformProperties,
239239
full_worker_logging: bool,
240240
) -> Option<WorkerId> {
241+
// Do a fast check to see if any workers are available at all for work allocation
242+
if !self.workers.iter().any(|(_, w)| w.can_accept_work()) {
243+
if full_worker_logging {
244+
info!("All workers are fully allocated");
245+
}
246+
return None;
247+
}
248+
241249
// Use capability index to get candidate workers that match STATIC properties
242250
// (Exact, Unknown) and have the required property keys (Priority, Minimum).
243251
// This reduces complexity from O(W × P) to O(P × log(W)) for exact properties.

nativelink-service/tests/worker_api_server_test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,7 @@ pub async fn workers_only_allow_max_tasks() -> Result<(), Box<dyn core::error::E
623623
"Expected not to be able to give worker a second task"
624624
);
625625

626-
assert!(logs_contain(
627-
"cannot accept work: is_paused=false, is_draining=false, inflight=1/1"
628-
));
626+
assert!(logs_contain("All workers are fully allocated"));
629627

630628
Ok(())
631629
}

0 commit comments

Comments
 (0)