Phi Accrual Detector

easy · distributed-systems, failure-detection, gossip

Phi Accrual Detector

A phi accrual failure detector converts time since the last heartbeat into a numeric suspicion level. For an exponential distribution of heartbeat intervals, phi can be approximated as:

phi = (elapsed / mean) / ln(10)

Given:

  • elapsedMs: milliseconds since the last heartbeat
  • meanMs: expected mean heartbeat interval (ms)
  • threshold: the suspicion threshold

Return the computed phi and whether the node is suspect (phi >= threshold).

Function signature

func PhiAccrual(elapsedMs, meanMs int64, threshold float64) (phi float64, suspect bool)

Example

elapsedMs = 1000
meanMs    = 1000
threshold = 1.0
phi       ~ 0.4343
suspect   = false

Constraints

  • meanMs > 0
  • elapsedMs >= 0

Notes

  • Use math.Ln10 for the natural log of 10.
Run tests to see results
No issues detected