jlholm / phi_accrual_detector

Ruby implementation of the "Phi Accrual Failure Detector"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PhiAccrual::FailureDetector

TODO: Delete this and the text above, and describe your gem

Ruby implementation of the "Phi Accrual Failure Detector".

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add phi_accrual_detector

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install phi_accrual_detector

Usage

detector = PhiAccrual::FailureDetector.new

# -------------
# Node is alive
# -------------
5.times do
  detector.heartbeat
  puts detector.phi
  sleep(rand(1..3))
end

# 0.07503303214093988
# 0.06063812103220427
# 0.036998235855052186
# 0.02462030950700087
# 0.016479458426418448


# ---------------------------------------------------
# Node crashed (detector is not receiving heartbeats)
# ---------------------------------------------------
5.times do
  puts detector.phi
  sleep(rand(1..3))
end

# 0.30195881305957445
# 1.432445140134964
# 5.822804423233738
# 8.431298445212251
# 21.485339424981944

# ---------------------
# Node is alive again
# ---------------------
5.times do
  detector.heartbeat
  puts detector.phi
  sleep(rand(1..3))
end

# 0.08297216512073446
# 0.08250671947626712
# 0.08142672282965253
# 0.08014861030851919
# 0.07861022577686376

Public methods

detector = PhiAccrual::FailureDetector.new

detector.heartbeat
detector.heartbeat_at(timestamp_in_ms)

detector.phi
detector.phi_at(timestamp_in_ms)

detector.available?
detector.available_at?(timestsamp_in_ms)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/phi_accrual_detector.

License

The gem is available as open source under the terms of the MIT License.

About

Ruby implementation of the "Phi Accrual Failure Detector"

License:MIT License


Languages

Language:Ruby 98.5%Language:Shell 1.5%