Code Monkey home page Code Monkey logo

ex-election's Introduction

Initial task description:

#################################

Simple group leader election

  • Processes can communicate with themselves only (e.g no ETS)

  • Each process is identified by id = integer()

  • The leader is the process with the greatest id

  • When process joins the group, it can reach any process. It should reply with:

  • pids of processes in the group

  • {pid, id} of the leader

New process should verify if it should become leader (highest id). If it is a leader, it should let know other nodes that there is a new leader.

  • The leader has responsibility to ackowledge all processes in the group.
  • If ping from leader is missing, the node with the highest id should become a leader.

#################################

Finaly it should auto-balance

Try to use (M is already a correct alias):


{:ok, p12} = M.start_link 12
{:ok, p1} = M.start_link 1
{:ok, p15} = M.start_link 15
{:ok, p3} = M.start_link 3
{:ok, p25} = M.start_link 25
{:ok, p7} = M.start_link 7

# wait till election is done, console should get 5 debug log messages from node 25 every 5 seconds
# you can check process states with:

M.inspect_state p12
M.inspect_state p1

M.inspect_state p25

# it is possible to clear a certain process members list to check if its come back from the leader:

M.clear_members p1
M.inspect_state p1

# Also we can kill any member:

M.inspect_state p25
GenServer.stop p1
M.inspect_state p25

# We can stop the leader and see what's happened:
GenServer.stop p25

# wait till reelection, console should get debug log messages from node 15

M.inspect_state p12
M.inspect_state p15

# also we can add new members any time:

{:ok, p29} = M.start_link 29
{:ok, p27} = M.start_link 27
{:ok, p28} = M.start_link 28
{:ok, p26} = M.start_link 26

M.inspect_state p29

# Process registry:

M.inspect_registry()

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.