PhiFailureDetector 2.0.2

dotnet add package PhiFailureDetector --version 2.0.2
                    
NuGet\Install-Package PhiFailureDetector -Version 2.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PhiFailureDetector" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PhiFailureDetector" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="PhiFailureDetector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PhiFailureDetector --version 2.0.2
                    
#r "nuget: PhiFailureDetector, 2.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PhiFailureDetector@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PhiFailureDetector&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=PhiFailureDetector&version=2.0.2
                    
Install as a Cake Tool

Phi Failure Detector

A high-performance implementation of the phi accrual failure detector for distributed systems in .NET.

Overview

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.

Features

  • Adaptive Detection: Automatically adjusts to network conditions and system load
  • Statistical Analysis: Uses historical heartbeat data for accurate failure prediction
  • Configurable Thresholds: Customizable phi values for different reliability requirements
  • High Performance: Optimized for low-latency distributed systems
  • Multi-Framework Support: Compatible with .NET Standard 2.0+, .NET Framework 4.6.2+, .NET 8.0, and .NET 9.0
  • Multiple Distribution Models: Supports both exponential and normal distribution models
  • Thread-Safe: Designed for concurrent usage in distributed systems

Installation

dotnet add package PhiFailureDetector

Quick Start

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;

Advanced Usage

Using Normal Distribution Model

// For more regular heartbeat patterns, use normal distribution
var detector = new PhiFailureDetector(
    capacity: 100,
    initialHeartbeatInterval: 1000,
    timeProvider: TimeProvider.System,
    phiFunc: PhiFailureDetector.Normal
);

Custom Time Provider

// 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
);

Monitoring Node Health

// 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();
    }
}

Phi Value Interpretation

The phi value represents the suspicion level of node failure:

  • 0-3: Low suspicion - Node is likely healthy
  • 3-8: Medium suspicion - Some concern about node health
  • 8+: High suspicion - Node is likely failed (99.999% confidence)

Common threshold values:

  • 3.0: 99.9% confidence of failure
  • 8.0: 99.999% confidence of failure (recommended for production)
  • 16.0: 99.99999% confidence of failure (very conservative)

Performance Considerations

  • The detector maintains a sliding window of heartbeat intervals for statistical analysis
  • Memory usage is proportional to the configured capacity
  • Calculation complexity is O(1) for both reporting heartbeats and calculating phi values
  • Thread-safe operations allow concurrent access from multiple threads

Algorithm Reference

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:

  1. Exponential Distribution: Suitable for Poisson processes (random message intervals)
  2. Normal Distribution: Suitable for regular heartbeat patterns with typical jitter

License

Licensed under GPLv3. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request to the OneDotNet repository.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 0 7/16/2025
1.0.0 1,419 12/31/2017
0.1.1 1,288 10/17/2017

# Release Notes
## Version 2.0.2
### Features
- Initial release of the Phi Failure Detector implementation
- Support for .NET Standard 2.0, 2.1, .NET Framework 4.6.2, .NET 8.0, and .NET 9.0
- Adaptive failure detection algorithm based on statistical analysis
- Configurable phi thresholds for different reliability requirements
- High-performance implementation optimized for distributed systems
- Comprehensive unit tests and documentation
### API
- `PhiFailureDetector` class for failure detection
- `Heartbeat()` method to record node activity
- `IsAvailable()` method to check node availability
- `Phi()` method to get current suspicion level
- `IWithStatistics` interface for statistical monitoring
### Dependencies
- Microsoft.Bcl.TimeProvider is required only for .NET Standard 2.0, .NET Standard 2.1, and .NET Framework 4.6.2. For .NET 8.0 and .NET 9.0, TimeProvider is built into the runtime and no package reference is needed.
### Documentation
- Complete API documentation
- Usage examples and best practices
- Algorithm explanation and references