npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

raftjs

v0.0.1

Published

Raft.js is an implementation of the Raft Consensus Algorithm

Downloads

7

Readme

Raft.js: Raft Consensus Algorithm in JavaScript

Raft.js is an implementation of the Raft consensus algorithm in JavaScript. The Raft algorithm was developed by Diego Ongaro and John Ousterhout at Stanford University. Please refer to their excellent paper on Raft: "In Search of an Understandable Consensus Algorithm".

Example

Start a node REPL and require one of the test modules.

> t = require('./test_local');
# OR
> t = require('./test_http');

The local test module starts servers in the same process that communicate directly with function calls. The http test creates servers in the same process but they communicate with each other by sending messages over HTTP.

Start 3 servers (an optional second argument specifies the number of servers to start):

> t.startServers({debug:true});

Get the leader ID and show its entry log:

> lid = t.getLeaderId();
> t.getAll('log')[lid];

Set a key/value in the state machine, show the log and stateMachine for all the servers, then read back the value:

> t.serverPool[lid].clientRequest({op:"set",key:'a',value:1}, function(results) { console.log("results: ", results); });
> t.getAll('log');
> t.getAll('stateMachine');
> t.serverPool[lid].clientRequest({op:"get",key:'a',ro:1}, function(results) { console.log("results: ", results); });

Add a new server (ID 3), set a different value and show that it has propagated to all the server state machines:

> t.addServer(3,{debug:true});
> t.serverPool[lid].clientRequest({op:"set",key:'b',value:2}, function(results) { console.log("results: ", results); });
> t.getAll('stateMachine');

Status

The following features have been implemented (the section number of the Raft paper is listed in brackets):

  • [5.2] Leader election
  • [5.3] Log replication and persistence
  • [5.4, 5.5, 5.6, 5.7] Safety features
  • [7.1] Client interaction (except filtering duplicates)
  • [5.1] RPCs:
  • In-process (direct function calls) for quick testing
  • Over HTTP
  • [6] Membership change / joint consensus

TODO

  • [7.1] filter duplicate client requests
  • [7.2] log compaction
  • faster resend of appendEntries when follower responds with fail (nextIndex update)
  • faster re-issue of requestVote to non-responders
  • more exception handling
  • in depth testing

License

Licensed under MPL-2.0. See LICENSE.txt.