File tree Expand file tree Collapse file tree
crates/hyperqueue/src/server/autoalloc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -355,7 +355,14 @@ async fn perform_submits(
355355 return Ok ( ( ) ) ;
356356 }
357357
358- // TODO: do not run the code below if all queues have full backlog anyway
358+ // If there is no allocation that we could possibly create, then stop
359+ if queues
360+ . iter ( )
361+ . all ( |( _, queue) | !queue. has_space_for_submit ( ) )
362+ {
363+ return Ok ( ( ) ) ;
364+ }
365+
359366 let queries: Vec < WorkerTypeQuery > = queues
360367 . iter ( )
361368 . map ( |( id, queue) | {
@@ -470,11 +477,7 @@ fn compute_submission_permit(
470477) -> SubmissionPermit {
471478 let info = queue. info ( ) ;
472479
473- // How many workers are currently already queued or running?
474- let active_workers = queue
475- . active_allocations ( )
476- . map ( |allocation| allocation. target_worker_count as u32 )
477- . sum :: < u32 > ( ) ;
480+ let active_workers = queue. active_worker_count ( ) ;
478481 let queued_allocs = queue. queued_allocations ( ) . collect :: < Vec < _ > > ( ) ;
479482
480483 let mut max_remaining_workers_to_spawn = match info. max_worker_count ( ) {
Original file line number Diff line number Diff line change @@ -252,6 +252,26 @@ impl AllocationQueue {
252252 pub fn get_worker_config ( & self ) -> Option < & WorkerConfiguration > {
253253 self . worker_config . as_ref ( )
254254 }
255+
256+ /// How many workers are currently queued or running?
257+ pub fn active_worker_count ( & self ) -> u32 {
258+ self . active_allocations ( )
259+ . map ( |allocation| allocation. target_worker_count as u32 )
260+ . sum :: < u32 > ( )
261+ }
262+
263+ /// Returns true only if at least a single allocation could be added to this queue.
264+ pub fn has_space_for_submit ( & self ) -> bool {
265+ if self . queued_allocations ( ) . count ( ) >= self . info . backlog ( ) as usize {
266+ return false ;
267+ }
268+ if let Some ( max_worker_count) = self . info . max_worker_count ( ) {
269+ if self . active_worker_count ( ) >= max_worker_count {
270+ return false ;
271+ }
272+ }
273+ true
274+ }
255275}
256276
257277// Allocation
You can’t perform that action at this time.
0 commit comments