Schedule unconscious agents by oldest last_run
Pick the agent that ran longest ago (or never) instead of scanning alphabetically. Fairness via min_by_key(last_run). Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
parent
74945e5754
commit
be44a3bb0d
1 changed files with 8 additions and 11 deletions
|
|
@ -187,17 +187,14 @@ impl Unconscious {
|
||||||
}
|
}
|
||||||
|
|
||||||
let running = self.agents.iter().filter(|a| a.is_running()).count();
|
let running = self.agents.iter().filter(|a| a.is_running()).count();
|
||||||
if running >= self.max_concurrent { return; }
|
for _ in running..self.max_concurrent {
|
||||||
let slots = self.max_concurrent - running;
|
let next = self.agents.iter().enumerate()
|
||||||
|
.filter(|(_, a)| a.should_run())
|
||||||
let ready: Vec<usize> = self.agents.iter().enumerate()
|
.min_by_key(|(_, a)| a.last_run);
|
||||||
.filter(|(_, a)| a.should_run())
|
match next {
|
||||||
.map(|(i, _)| i)
|
Some((idx, _)) => self.spawn_agent(idx).await,
|
||||||
.take(slots)
|
None => break,
|
||||||
.collect();
|
}
|
||||||
|
|
||||||
for idx in ready {
|
|
||||||
self.spawn_agent(idx).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue