Git Product home page Git Product logo

pontoon's Introduction

Pontoon

Build Status Gem Version

Pontoon is a Ruby implementation of the Raft algorithm.

Raft is a distributed consensus algorithm designed to be easy to understand. The algorithm is the work of Diego Ongaro and John Ousterhout at Stanford University. The implementation here is based upon this paper.

Technical Design

This gem provides a Pontoon::Node class that handles log replication across a cluster of peer nodes. Design decisions about the RPC protocol, concurrency mechanism, error handling and data persistence are left to the client. For convenience and testing, an example implementation is provided based on Goliath and EventMachine, with in-memory data persistence. Contributions of further examples are very welcome!

Usage

Install the gem:

gem install pontoon

In your code, add a require:

require 'pontoon'

If you'd like to use the example Goliath implementation, add:

require 'pontoon/goliath'

Pontoon replicates commands across a cluster of nodes. Each node in the cluster is aware of every other node in the cluster. Let's create a new cluster and define its configuration:

@cluster = Pontoon::Cluster.new('alpha', 'beta', 'gamma')

@config = Pontoon::Config.new(
  rpc_provider,       # see Pontoon::RpcProvider
  async_provider,     # see Pontoon::AsyncProvider
  election_timeout,   # in seconds
  election_splay,     # in seconds
  update_interval,    # in seconds
  heartbeat_interval) # in seconds

Now we can create Pontoon nodes for each node defined in the cluster:

@nodes = @cluster.node_ids.map do |node_id|
  Pontoon::Node.new(node_id, @config, @cluster)
end

Since the concurrency mechanism is left to the client, you must call Pontoon::Node#update regularly to allow the node to participate in the cluster:

# Threaded example:
@update_threads = @nodes.map do |node|
 Thread.new do
   while true
     node.update
     sleep(node.config.update_interval)
   end
 end
end
# Evented example
@update_timers =  @nodes.map do |node|
  EventMachine.add_periodic_timer(node.config.update_interval) do
    EM.synchrony do
      node.update
    end
  end
end

We can send commands (which are strings) to the cluster and they will be appended to the command log, which will be replicated across the cluster.

command = 'example'
request = Pontoon::CommandRequest.new(command)
node = @nodes.sample
response = node.handle_command(request) # response is a Pontoon::CommandResponse

Note that Pontoon::Node#handle_command will not return success until the command has been replicated to a majority of nodes, so that it is considered committed and is safe to execute.

If you would like to execute commands as they are committed, you can assign a commit handler for each node:

@nodes.each do |node|
  node.commit_handler = Proc.new do |command|
    puts "Node #{node.id} executing command #{command}!"
  end
end

Issues and Feedback

If you encounter problems with this gem, please feel free to raise an issue.

Contributing

Fork this repository and make a pull request!

License

Pontoon is released under the MIT license.

pontoon's People

Contributors

anthonycorletti avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.