mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-20 05:23:44 +00:00
add a short sleep in the supervisor's event loop to reduce CPU usage (#1080)
This commit is contained in:
@ -14,6 +14,7 @@ use crate::work::IWorkQueue;
|
|||||||
use crate::worker::IWorkerRunner;
|
use crate::worker::IWorkerRunner;
|
||||||
|
|
||||||
const PENDING_COMMANDS_DELAY: time::Duration = time::Duration::from_secs(10);
|
const PENDING_COMMANDS_DELAY: time::Duration = time::Duration::from_secs(10);
|
||||||
|
const BUSY_DELAY: time::Duration = time::Duration::from_secs(1);
|
||||||
|
|
||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
coordinator: Box<dyn ICoordinator>,
|
coordinator: Box<dyn ICoordinator>,
|
||||||
@ -231,6 +232,15 @@ impl Agent {
|
|||||||
async fn busy(&mut self, state: State<Busy>) -> Result<Scheduler> {
|
async fn busy(&mut self, state: State<Busy>) -> Result<Scheduler> {
|
||||||
self.emit_state_update_if_changed(StateUpdateEvent::Busy)
|
self.emit_state_update_if_changed(StateUpdateEvent::Busy)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Without this sleep, the `Agent.run` loop turns into an extremely tight loop calling
|
||||||
|
// `wait4` of the running agents. This sleep adds a small window to allow the rest of the
|
||||||
|
// system to work. Emperical testing shows this has a significant reduction in CPU use.
|
||||||
|
//
|
||||||
|
// TODO: The worker_runner monitoring needs to be turned into something event driven. Once
|
||||||
|
// that is done, this sleep should be removed.
|
||||||
|
time::sleep(BUSY_DELAY).await;
|
||||||
|
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
let updated = state
|
let updated = state
|
||||||
.update(&mut events, self.worker_runner.as_mut())
|
.update(&mut events, self.worker_runner.as_mut())
|
||||||
|
Reference in New Issue
Block a user