MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / heartbeat_interval_with_jitter

Function heartbeat_interval_with_jitter

nodedb/src/data/runtime.rs:416–429  ·  view source on GitHub ↗

Compute heartbeat interval with ±100ms jitter. Returns a Duration in the range [900ms, 1100ms]. The jitter spreads heartbeat emissions across cores so they don't all fire in the same poll iteration when the system goes idle. Uses a fast splitmix64-style hash of the current timestamp nanos to produce pseudo-random jitter without requiring the `rand` crate in production code (it's dev-only).

()

Source from the content-addressed store, hash-verified

414/// produce pseudo-random jitter without requiring the `rand` crate in
415/// production code (it's dev-only).
416fn heartbeat_interval_with_jitter() -> std::time::Duration {
417 let seed = std::time::SystemTime::now()
418 .duration_since(std::time::UNIX_EPOCH)
419 .unwrap_or_default()
420 .as_nanos() as u64;
421 // splitmix64
422 let mut x = seed;
423 x ^= x >> 30;
424 x = x.wrapping_mul(0xbf58476d1ce4e5b9);
425 x ^= x >> 27;
426 // Map to [0, 200] → offset by -100 → [-100, +100] ms.
427 let jitter_ms = (x % 201) as i64 - 100;
428 std::time::Duration::from_millis((1000 + jitter_ms) as u64)
429}
430
431/// Extract a human-readable message from a panic payload.
432fn panic_message(payload: &Box<dyn std::any::Any + Send>) -> String {

Callers 1

spawn_coreFunction · 0.85

Calls 2

nowFunction · 0.85
duration_sinceMethod · 0.80

Tested by

no test coverage detected