1. afd(3)
  2. afd(3)


afd - Accrual Failure Detector


var afd = require('afd')

instance afd([number ws=100], [number last=Date.now()])

void .report([number when])

number .phi([number when])


$ npm install afd

$ component install afd


afd is a node.js implementation of The Phi Accrual Failure Detector.

Based (roughly) on the version from Cassandra, which is based on the paper The Phi Accrual Failure Detector by Naohiro Hayashibara.

It's also a mix between racker/node-failure-detector and bpot/node-gossip/accrual_failure_detector.js.

The Phi Accrual Failure Detector is commonly used to detect failure of a peer in a distributed system.


instance afd([number ws=100], [number last=Date.now()])

Creates a new instance of afd that keeps the state of one peer. ws defines the number of timestamps to keep in the peer history, last defines the initial timestamp that the peer starts with.

void .report([number when=Date.now()])

Reports a successful signal from the peer. By calling report you're saying that in the defined timestamp, the peer is alive. when states the timestamp of the signal.

number .phi([number when=Date.now()])

Get the current phi of the peer. Optionally you can get the phi in a specific timestamp. The higher the Phi, the bigger the confidence that the peer has failed.


$ make test

$ make test-browser


var afd = require('afd')
var peers = {}

server.on('message', function(msg) {
  if(msg.type !== 'ping') return
  if(!peers[server.id]) peers[server.id] = afd()

setInterval(function() {
  Object.keys(peers).forEach(function (id) {
    if(peers[id].phi() > 8) console.error('Node %s has probably failed!', id)
    else console.log('Node %s is alive!', id)
}, 1000)



  1. Kordon
  2. June 2013
  3. afd(3)