Avoid performance overhead. Add comments on why we check the handling time.tags/v0.3.12-rc0
| @@ -197,8 +197,9 @@ async fn start_inner( | |||
| let mut daemon_connections = DaemonConnections::default(); | |||
| while let Some(event) = events.next().await { | |||
| // used below for measuring the event handling duration | |||
| let start = Instant::now(); | |||
| let event_debug = format!("{event:?}"); | |||
| let event_kind = event.kind(); | |||
| if event.log() { | |||
| tracing::trace!("Handling event {event:?}"); | |||
| @@ -738,10 +739,11 @@ async fn start_inner( | |||
| }, | |||
| } | |||
| // warn if event handling took too long -> the main loop should never be blocked for too long | |||
| let elapsed = start.elapsed(); | |||
| if elapsed > Duration::from_millis(100) { | |||
| tracing::warn!( | |||
| "Coordinator took {}ms for handling event: {event_debug}", | |||
| "Coordinator took {}ms for handling event: {event_kind}", | |||
| elapsed.as_millis() | |||
| ); | |||
| } | |||
| @@ -1154,6 +1156,22 @@ impl Event { | |||
| _ => true, | |||
| } | |||
| } | |||
| fn kind(&self) -> &'static str { | |||
| match self { | |||
| Event::NewDaemonConnection(_) => "NewDaemonConnection", | |||
| Event::DaemonConnectError(_) => "DaemonConnectError", | |||
| Event::DaemonHeartbeat { .. } => "DaemonHeartbeat", | |||
| Event::Dataflow { .. } => "Dataflow", | |||
| Event::Control(_) => "Control", | |||
| Event::Daemon(_) => "Daemon", | |||
| Event::DaemonHeartbeatInterval => "DaemonHeartbeatInterval", | |||
| Event::CtrlC => "CtrlC", | |||
| Event::Log(_) => "Log", | |||
| Event::DaemonExit { .. } => "DaemonExit", | |||
| Event::DataflowSpawnResult { .. } => "DataflowSpawnResult", | |||
| } | |||
| } | |||
| } | |||
| #[derive(Debug)] | |||
| @@ -320,8 +320,9 @@ impl Daemon { | |||
| tracing::warn!("failed to update HLC with incoming event timestamp: {err}"); | |||
| } | |||
| // used below for checking the duration of event handling | |||
| let start = Instant::now(); | |||
| let event_debug = format!("{inner:?}"); | |||
| let event_kind = inner.kind(); | |||
| match inner { | |||
| Event::Coordinator(CoordinatorEvent { event, reply_tx }) => { | |||
| @@ -430,10 +431,11 @@ impl Daemon { | |||
| } | |||
| } | |||
| // warn if event handling took too long -> the main loop should never be blocked for too long | |||
| let elapsed = start.elapsed(); | |||
| if elapsed > Duration::from_millis(100) { | |||
| tracing::warn!( | |||
| "Daemon took {}ms for handling event: {event_debug}", | |||
| "Daemon took {}ms for handling event: {event_kind}", | |||
| elapsed.as_millis() | |||
| ); | |||
| } | |||
| @@ -2152,6 +2154,24 @@ impl From<DoraEvent> for Event { | |||
| } | |||
| } | |||
| impl Event { | |||
| pub fn kind(&self) -> &'static str { | |||
| match self { | |||
| Event::Node { .. } => "Node", | |||
| Event::Coordinator(_) => "Coordinator", | |||
| Event::Daemon(_) => "Daemon", | |||
| Event::Dora(_) => "Dora", | |||
| Event::DynamicNode(_) => "DynamicNode", | |||
| Event::HeartbeatInterval => "HeartbeatInterval", | |||
| Event::CtrlC => "CtrlC", | |||
| Event::SecondCtrlC => "SecondCtrlC", | |||
| Event::DaemonError(_) => "DaemonError", | |||
| Event::SpawnNodeResult { .. } => "SpawnNodeResult", | |||
| Event::SpawnDataflowResult { .. } => "SpawnDataflowResult", | |||
| } | |||
| } | |||
| } | |||
| #[derive(Debug)] | |||
| pub enum DaemonNodeEvent { | |||
| OutputsDone { | |||