Skip to content

Latest commit

 

History

History
152 lines (85 loc) · 3.41 KB

doc.md

File metadata and controls

152 lines (85 loc) · 3.41 KB

failured

import "github.com/andy2046/failured"

Package failured implements the Adaptive Accrual Failure Detector

This package implements [A New Adaptive Accrual Failure Detector for Dependable Distributed Systems](https://dl.acm.org/citation.cfm?id=1244129)

To use the failure detector, you need a heartbeat loop that will call RegisterHeartbeat() at regular intervals. At any point, you can call FailureProbability() which will report the suspicion level since the last time RegisterHeartbeat() was called.

failured.go

var (
    // DefaultConfig is the default Detector Config.
    DefaultConfig = Config{
        WindowSize:       1000,
        Factor:           0.9,
        FailureThreshold: 0.5,
    }
)
type Config struct {
    // max size of inter-arrival time list
    WindowSize uint64
    // a scaling factor
    Factor float64

    FailureThreshold float64
}

Config used to init Detector.

type Detector struct {
    // contains filtered or unexported fields
}

Detector is a failure detector.

func New(options ...Option) *Detector

New returns a new failure detector.

func (*Detector) CheckFailure

func (d *Detector) CheckFailure(now ...int64) bool

CheckFailure returns true if FailureProbability is equal to or higher than FailureThreshold. now is the current time in Microseconds.

func (d *Detector) FailureProbability(now ...int64) float64

FailureProbability calculates the suspicion level at time now that the remote end has failed. now is the current time in Milliseconds, default to time.Now() in Milliseconds.

func (d *Detector) RegisterHeartbeat(now ...int64)

RegisterHeartbeat registers a heartbeat at time now. now is the time in Milliseconds at which the heartbeat was received, default to time.Now() in Milliseconds.

type Option = func(*Config) error

Option applies config to Detector Config.


Generated by godoc2md