Giter VIP home page Giter VIP logo

erldemo's Introduction

demo

This is an small Erlang application demostrating some of the features of Erlang/OTP.

How to read the code

I commented the core modules heavily. So hopefully they can be read by those having no prior exposure to Erlang whatsoever.

The recommended order is below:

  1. src/coordinator.erl

    Implements the coordinator behavior that accepts abstract CPU-intensive jobs, deduplicates them when possible, computes job results limiting maximum parallelism.

  2. src/demo_worker.erl

    Instantiates the coordinator behavior telling it how to compute Fibonacci numbers (in a way that is deliberately very slow).

    An instance of this process will be running on each Erlang node.

  3. src/demo.erl

    A wrapper module that distributes jobs to demo_worker processes an connected nodes using consistent hashing.

  4. src/demo_rest.erl

    Optional (as I didn't leave any comments here). This module exposes the APIs exposed by demo via HTTP.

Build

$ rebar3 compile
$ rebar3 release

Run

First node

$ ./start.sh --node [email protected] --cookie secret --port 8080

Second node

$ ./start.sh --node [email protected] --cookie secret --bootstrap [email protected] --port 8081

APIs

Get statistics

$ curl -s -XGET http://127.0.0.1:8080/stats | jq .
{
  "[email protected]": {
    "ok": 129,
    "failed": 0,
    "computed_ok": 88,
    "computed_failed": 0,
    "accepted": 135
  }
}

Reset statistics

$ curl -s -XDELETE http://127.0.0.1:8080/stats | jq .
"ok"

Compute the N-th Fibonacci number

$ curl -s -XGET http://127.0.0.1:8080/fibonacci/42 | jq .
{
  "result": 433494437,
  "n": 42
}

erldemo's People

Contributors

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