Coder Social home page Coder Social logo

gen_cluster's Introduction

gen_cluster

Summary

gen_cluster is an erlang behavior for pid clustering. It is a cascading behavior that builds on gen_server.

Status

Early alpha. Feel free to use this in production code as long as you know that nobody else is.

Motivation

Erlang provides many BIFs for dealing with nodes, node clustering, monitoring etc. However, one often wants to build a cluster of processes rather than entire nodes.

This module is a starting point for creating your own gen_server clusters. It aims to deal with common roles, actions, and callbacks one often deals with when making a cluster.

As usual, there are a number of subtleties that crop up when trying to create a cluster. The goal is for gen_cluster to allow one to gloss-over these details and simply provide an easy-to-use foundation for cluster-based erlang projects.

Features

Current features include:

  • Joining a cluster based on a given seed node
  • Storing the list of all current nodes in the cluster
  • Callbacks when a node joins or leaves

Usage

Add the behaviour directive to your module, implement the callbacks for both gen_server and gen_cluster. See example_cluster_srv.erl for full example and function signatures.

-behaviour(gen_cluster).

% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

% gen_cluster callback
-export([handle_join/3, handle_node_joined/3, handle_leave/4]).

Try it out

Open up three terminals and do the following commands. This will start up three nodes that will join the first node. On q(). of any one of the nodes the other two will see that the node left and update the pidlist accordingly.

# term 1
rake server:start1

# term 2
rake server:start2

# term 3
rake server:start3

# term 2 again
q().

Plans

(features not yet implemented)

  • Globally registered name needs to be taken over by another node if the globally registered node dies. This is an important TODO and will be handled shortly.
  • TCP-layer option, rather than straight distributed erlang
  • Possible integration with Chordjerl

Authors

  • Nate Murray <nmurray [AT] attinteractive.com> github
  • Ari Lerner github

gen_cluster's People

Contributors

jashmenn avatar auser avatar

Stargazers

Niranjan Anandkumar avatar Mikal avatar Medson Oliveira avatar Sora Morimoto avatar Jeremy  avatar Leonardo Rossi avatar Alex Constandache avatar  avatar Gregory Haskins avatar Marko Mikulicic avatar Stone Gao avatar Martin Pompéry avatar edwardt avatar Andrey Popp avatar  avatar Yurii Rashkovskii avatar

Watchers

 avatar  avatar edwardt avatar James Cloos avatar edwardttril avatar  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.