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

@pontal/hubraft

v0.2.2

Published

Election only raft like implementation designed for resilient overseers

Downloads

5

Readme

Hubraft concepts

Hubraft is a NodeJs partial implementation of The Raft Consensus Algorithm, aiming to fullfil the needs of resilient applications that can't run in parallel.

alt text

Hubraft does the election of nodes when the leader stop sending hearbeats, but does not implements data replication.

Install

npm install --save @pontal/hubraft

Initializing

const hubraft = require('@pontal/hubraft')(
    heartbeatInterval: 300, // optional
    minElectionTimeout: 800, // optional
    maxElectionTimeout: 1000, // optional
    name: 'master', // required
    host: 'master.example.com', // required
    port: 9899, // required
    nodes: [{ // required
        name: 'backup1',
        host: 'backup1.example.com',
        port: 9899,
    }, {
        name: 'backup2',
        host: 'backup2.example.com',
        port: 9899,
    }]
);

Options

  • heartbeatInterval: (optional) in milliseconds, defaults to 300ms
  • minElectionTimeout: (optional) in milliseconds, defaults to 800ms
  • maxElectionTimeout: (optional) in milliseconds, defaults to 1000ms
  • name: (required) slug that identifies the application node
  • host: (required) the hostname/ip which application is running
  • port: (required) port which hubraft should listen
  • nodes: (required) other nodes of the application (array of name, host, port objects)

How it works

The Hubraft emits the following events :

  • becomeLeader
  • becomeFollower
  • becomeCandidate

- becomeLeader

When the server is elected leader the event "becomeLeader" is sent to other servers, and to apply some type to behavior, use this script:

const hubraft = require('@pontal/hubraft');

let options = {...};

const hub = hubraft.init(options);

hub.eventEmitter.on('becomeLeader', () => {
	// Start your application
}); 

- becomeFollower

The event "becomeFollower" is sent when another server is elected leader, this way the current server is left in "Stand by", and just keeps listening to the leader's heartbeat

const hubraft = require('@pontal/hubraft');

let options = {...};

const hub = hubraft.init(options);

hub.eventEmitter.on('becomeFollower', () => {
	// Stop your system
});

- becomeCandidate

The event "becomeCandidate" is sent when the server was a "Follower" and the leader stops sending the heartbeat, and by default when a server becomes a "Candidate", he automatically asks for an election.

Tests

"Jest" needed.

npm test