Git Product home page Git Product logo

electio's Introduction

electio

This project implements a distributed election algorithm. Without dependency, each node conversations with mates by http protocol. Distributed election algorithm, no runtime dependence.

Work steps:

  • 1.Start the goroutine 1 to Ping the peer node regularly.
  • 2.Start goroutine 2 to prepare to perform master function. If the current node is not a master, the goroutine is idle.
    1. The master goroutine checks the survival status of other nodes in the cluster. After more than half of the nodes are started:
  • 3.1. check whether there is a master in the existing cluster, and follow if there is;
  • 3.2.if there is no master after step 3.1, select a master according to the agreement and follow it. In this step, a master must be selected;
  • 3.3.if the master is himself after step 3.2, perform the master role and ask his peers to follow him;
  • 3.4.if the master node selected in step 3.2 follows another master 2, then forward following master 2 directly, and so on;
  • 4.The timeout can be set for the mutual Ping of goroutine 1. After the timeout, the peer is marked as inactive.
  • 5.If master timeout is found in goroutine 1, the master goroutine will be notified to initiate election.

Communication protocol:

Request content:

GET /ping?fromId=xxxx&masterId=xxxx

Respond contents:

type PingRes struct {
    Code int        // codes
    Msg string      // message
    WorkerId string // workerId of responder
    MasterId string // masterId of responder
    Members map [string] * worker / / map [masterid] * matched by worker responder
}

Constants

//Registered nodes, detect their timeout. After the normal node times out, it is marked as inactive. After the master time out, it will start the election.
const RegisterTimeoutSec = 2

//Time interval for periodic registration as worker to peer
const RegisterIntervalSec = 1

electio's People

Contributors

uxff 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.