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

ring-election

v1.1.0

Published

Leader and followers algorithm to make partitioning easy.

Downloads

38

Readme

Ring election

Is your dream to build a service like cassandra,kafka,zipkin,jaeger,redis,etc...? You are in the right place , join ring-election project !!!

Coverage Status Build Status Actions Status Codacy Badge Gitter chat JavaScript Style Guide

   docker-compose up 

Check assigned partitions to local:9000/status or change the port to 9001/9002 Try to stop and restart container and observe the behaviour. If you want to develop new features or fix a bug you can do that without docker images , just configure environment variables correctly ( you can see them on [docker-compose.yaml] file) . See Examples section to know how to integrate this library and build some distributed services on top of ring-election !!!

What the ring-election driver offers you ?

  • A default partitioner that for an object returns the partition to which it is assigned.
  • Mechanism of leader election
  • Failure detection between nodes.
  • Assignment and rebalancing of partitions between nodes
  • Automatic re-election of the leader

What problems can you solve with this driver ?

  • Scalability
  • High availability
  • Concurrency between nodes in a cluster
  • Automatic failover

This section introduce you on what you can build on top of ring-election using it as driver/library.

Distributed Scheduler Each Scheduler instance will work on the assigned partitions . A real implementation of this use case is available here https://github.com/pioardi/hurricane-scheduler Dynamic diagram

Distributed lock Distributed cache Distributed computing

const ring = require('ring-election');
let leader = ring.leader;
leader.createServer();
// if you want REST API as monitoring , invoke startMonitoring
leader.startMonitoring();
// to get ring info
ring.leader.ring();
// Your leader will be the coordinator.

How to follower

const ring = require('ring-election')
let follower = ring.follower
const {
  BECOME_LEADER,
  PARTITIONS_ASSIGNED,
  PARTITIONS_REVOKED
} = ring.constants;
follower.createClient()
// if you want REST API as monitoring , invoke startMonitoring
follower.startMonitoring()
// to get ring info
ring.follower.ring()
// to get assigned partitions
let assignedPartitions = ring.follower.partitions()
// now let me assume that a follower will create some data
// and you want to partition this data
let partition = ring.follower.defaultPartitioner('KEY')
// save your data including the partition on a storage
// you will be the only one in the cluster working on the partitions assigned to you.

// If you want to handle partitions assigned ( use other constants to listen other events ) you can do in this way.
ring.follower.eventListener.on(PARTITIONS_ASSIGNED , (newAssignedPartitions) => {
   // DO STUFF
})

Try it out !

   docker image build -t ring-election .
   docker-compose up

See examples folder for more advanced examples

Re-add a client in the cluster when it was removed and send an hearth beat Implement event emitter to notify library users when something happens

Dynamic diagram