Giter VIP home page Giter VIP logo

les's Introduction

Leader Election by Seniority (LES)

This algorithm came from a necessity to bounce an IP address between Cloud Server nodes. It can be used to implement and manage pretty much any resources though.

Python Implementation

A Python template for clustered leadership elections, where the most senior node wins.

Copy les-example.py and implement leader_changed().

The Algorithm Rules

  • Nodes share their memberlist upon request
  • Nodes will attempt to add new members when informed of the new node
  • Nodes will always retry seed nodes and add active seeds to the memberlist
  • Nodes will remove members it can't contact
  • Nodes can not do election until it has communicated with other nodes
  • Nodes will always accept the most senior node as the leader
  • If a node elects itself, it must wait for other members to confirm first, unless it's alone

Demo

You can just run 3 nodes locally with the following commands in separate terminals.

$ python3 les-example.py --bind-port 4000 --advertise-addr localhost:4000 --seeds localhost:4000,localhost:4001,localhost:4002
$ python3 les-example.py --bind-port 4001 --advertise-addr localhost:4001 --seeds localhost:4000,localhost:4001,localhost:4002
$ python3 les-example.py --bind-port 4002 --advertise-addr localhost:4002 --seeds localhost:4000,localhost:4001,localhost:4002

You can view the entire state via curl from any node:

$ curl -s localhost:4002/diag/
{
  "state": {
    "members": [
      "localhost:4002",
      "localhost:4000",
      "localhost:4001"
    ],
    "leader": "localhost:4000",
    "start_time": 1627515915.703066
  },
  "member_states": {
    "localhost:4000": {
      "members": [
        "localhost:4000",
        "localhost:4001",
        "localhost:4002"
      ],
      "leader": "localhost:4000",
      "start_time": 1627515912.646504
    },
    "localhost:4001": {
      "members": [
        "localhost:4001",
        "localhost:4000",
        "localhost:4002"
      ],
      "leader": "localhost:4000",
      "start_time": 1627515914.368885
    },
    "localhost:4002": {
      "members": [
        "localhost:4002",
        "localhost:4000",
        "localhost:4001"
      ],
      "leader": "localhost:4000",
      "start_time": 1627515915.703066
    }
  }
}

les's People

Contributors

protosam avatar

Stargazers

 avatar

Watchers

 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.