4 releases (breaking)
0.4.0 | Mar 2, 2024 |
---|---|
0.3.0 | Dec 9, 2020 |
0.2.0 | Dec 8, 2020 |
0.1.0 | Dec 7, 2020 |
#926 in Algorithms
264 downloads per month
Used in 3 crates
40KB
105 lines
phi-detector
This is a Rust implemention of Phi Accrual Failure Detector algorithm which is clearly described in the figure below. Using this algorithm you can detect remote server failure.
lib.rs
:
This is an implementation of Phi Accrual Failure Detector.
To reduce the memory footprint, pings or intervals aren't actually stored but only two values to calculate normal distribution are maintained. This not only reduces the memory footprint to the constant value but also the computational cost for each ping down to constant.
Why does the memory footprint matter? Think about your application communicates with thousand of remote servers and you want to maintain failure detector for each server. Apparently, it is too expensive to cost 100MB for a failure detector per server.
use phi_detector::PingWindow;
use std::time::Duration;
// Create a window with a interval 100ms.
let mut window = PingWindow::new(Duration::from_millis(100));
window.add_ping(Duration::from_millis(150));
window.add_ping(Duration::from_millis(80));
// Now the window has intervals [100ms, 150ms, 80ms]. Average is 110ms.
let normal_dist = window.normal_dist();
// If the server is down for 5s, it should be failure.
let phi = normal_dist.phi(Duration::from_millis(5000));
if phi > 12. {
panic!("The server is down");
}