Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
node/reactor: Introduce `LAG_TIMEOUT`
Lorenz Leutgeb committed 2 months ago
commit 057edf55b857783b27bef58b7177b0ffc41a6af6
parent ae06111
1 file changed +11 -0
modified crates/radicle-node/src/reactor.rs
@@ -34,6 +34,12 @@ const SECONDS_IN_AN_HOUR: u64 = 60 * 60;
/// Maximum amount of time to wait for I/O.
const WAIT_TIMEOUT: Duration = Duration::from_secs(SECONDS_IN_AN_HOUR);

+
/// Maximum duration to accept the service to spend handling events (and errors,
+
/// ticking, etc.) without warning. Set to log whenever the service becomes so
+
/// is so slow to respond that it would not be able to handle at least 10
+
/// "requests" per second, i.e. `1s / 10 = 100ms`.
+
const LAG_TIMEOUT: Duration = Duration::from_millis(100);
+

/// A resource which can be managed by the reactor.
pub trait EventHandler {
    /// The type of reactions which this resource may generate upon receiving
@@ -423,6 +429,11 @@ impl<H: ReactionHandler> Runtime<H> {
                }
            }

+
            let duration = Instant::now().duration_since(tick);
+
            if duration > LAG_TIMEOUT {
+
                log::warn!(target: "reactor", "Service was busy {:?} which exceeds the timeout of {:?}", duration, LAG_TIMEOUT);
+
            }
+

            self.handle_actions(tick);
        }
    }