An implementation of the phi accrual failure detector for distributed systems. Based on the paper by N. Hayashibara, X. Defago, R. Yared, and T. Katayama, providing adaptive failure detection with configurable thresholds and statistical analysis.
Deps
3
Install Size
—
Vulns
✓ 0
Published
Aug 22, 2025
$ dotnet add package PhiFailureDetectorA high-performance implementation of the phi accrual failure detector for distributed systems in .NET.
The Phi Failure Detector is an adaptive failure detection algorithm that provides more accurate and flexible failure detection compared to traditional timeout-based approaches. It uses statistical analysis of heartbeat intervals to calculate a phi value that represents the suspicion level of a node failure.
dotnet add package PhiFailureDetector
using PhiFailureDetector;
// Create a failure detector with exponential distribution model
var detector = new PhiFailureDetector(
capacity: 100, // Number of samples to keep
initialHeartbeatInterval: 1000, // Initial interval in milliseconds
timeProvider: TimeProvider.System, // Time provider
phiFunc: PhiFailureDetector.Exponential // Distribution model
);
// Record heartbeats when they arrive
detector.Report();
// Later, check the current phi value (suspicion level)
double phi = detector.Phi();
// A phi value above your threshold indicates suspected failure
// Common thresholds: 3.0 (99.9% confidence), 8.0 (99.999% confidence)
bool isSuspected = phi > 8.0;
// For more regular heartbeat patterns, use normal distribution
var detector = new PhiFailureDetector(
capacity: 100,
initialHeartbeatInterval: 1000,
timeProvider: TimeProvider.System,
phiFunc: PhiFailureDetector.Normal
);
// Use a custom time provider for testing or specific scenarios
var customTimeProvider = new MockTimeProvider();
var detector = new PhiFailureDetector(
capacity: 100,
initialHeartbeatInterval: 1000,
timeProvider: customTimeProvider,
phiFunc: PhiFailureDetector.Exponential
);
// Example of monitoring a distributed node
class NodeMonitor
{
private readonly PhiFailureDetector detector;
private readonly double failureThreshold = 8.0; // 99.999% confidence
public NodeMonitor()
{
detector = new PhiFailureDetector(
capacity: 200,
initialHeartbeatInterval: 5000, // 5 seconds
timeProvider: TimeProvider.System,
phiFunc: PhiFailureDetector.Exponential
);
}
public void OnHeartbeatReceived()
{
detector.Report();
}
public bool IsNodeSuspected()
{
return detector.Phi() > failureThreshold;
}
public double GetSuspicionLevel()
{
return detector.Phi();
}
}
The phi value represents the suspicion level of node failure:
Common threshold values:
3.0: 99.9% confidence of failure8.0: 99.999% confidence of failure (recommended for production)16.0: 99.99999% confidence of failure (very conservative)Based on the paper: "The φ accrual failure detector" by N. Hayashibara, X. Defago, R. Yared, and T. Katayama, published in Proceedings of the 23rd IEEE International Symposium on Reliable Distributed Systems, 2004.
The implementation provides two distribution models:
LGPL-3.0-or-later WITH LGPL-3.0-linking-exception. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request to the OneDotNet repository.
If you encounter any issues or have questions, please open an issue on GitHub.