• Stars
    star
    140
  • Rank 261,563 (Top 6 %)
  • Language
    Erlang
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Erlang Distributed Scheduler

GameAnalytics Cluster Scheduler

Build Status

This library implements a generic scheduler for processing tasks in a cluster. The generation and processing of tasks is specialized for a particular application. The client passes a callback to execute and a message is returned indicating the status of the task.

Tasks are controlled by a state machine depicted in the following diagram.

  execute(SchedulerName, MFA = {Mod, Fun, Args})
             |
             |
             v
    .--->[ Pending ]---.
    |                  |
node down         spawn worker
    |                  |
    `---[ Running ]<---'-----------.
        |         |                 |
        |     exception           retry
        |         |                 |
        |         `--->[ Failed ]---'
     success           |        |
        |        max retries  MFA called
        |         exceeded    throw(gascheduler_permanent_failure)
        |              |        |
        |              v        |
        |  {error, max_retries} |
        |                       v
        |                   {error, permanent_failure}
        v
{ok, Result = apply(Mod, Fun, Args)}

Only the states Pending and Running are represented inside the scheduler. Retries are handled on the worker nodes. Once tasks have finished they are no longer tracked by the scheduler.

A cluster consists of one or more nodes. Nodes have worker processes available to execute tasks. Typically the master node also has worker processes.

Example Usage

To start the scheduler some configuration is required to be passed in.

    %% Each gascheduler has its own name. There can be multiple gaschedulers.
    Name = test,

    %% A list of nodes to execute work on. See also erlang:nodes().
    Nodes = [...],

    %% Maximum number of workers per node.
    MaxWorkers = 10,

    %% Maximum number of retries for a worker, i.e. it throws some exception.
    MaxRetries = 10,

    %% Where to send scheduler status messages to.
    Client = self(),

    %% Start the scheduler.
    {ok, _} = gascheduler:start_link(Name, Nodes, Client, MaxWorkers, MaxRetries),

We can then run a task on the scheduler.

    %% Execute hello:world(1) asynchronously.
    %% In the hello module exists, world(N) -> N.
    ok = gascheduler:execute(Name, {hello, world, [1]}),

We are notified of task status asynchronously.

    %% Receive a single status message from a particular scheduler.
    receive
        {Name, {ok, Result}, Node, MFA = {Mod, Fun, Args}} ->
            io:format(“hello world ~p from ~p~n”, [Result, Node]);
        {Name, {error, Reason}, Node, MFA = {Mod, Fun, Args}} ->
            io:format(“task ~p failed on ~p because ~p”, [MFA, Node, Reason])
    end

When the task completes successfully.

    hello world 1 from slave1@worker1

Possible failure cases.

    task {hello, world, [1]} failed on slave1@worker1 because max_retries
    task {hello, world, [1]} failed on slave1@worker1 because permanent_failure

Caveats

The scheduler is a single master without redundancy. If the master is unavailable the entire system is unavailable.

The callback being executed by the scheduler may be executed more than once if communication is lost to a node but is still running. In this case the scheduler will receive a node down message due to loss of communication. It will then reschedule the task on another available node. However, the task may continue running on the node which has lost communication. Therefore, the callback has to be safe if it is run more than once.

Do we actually use this code?

The gascheduler code is in production use at Game Analytics. We definitely find it useful.

Slides

You can find slides about gascheduler here. This was presented at the Erloung Berlin Erlang Meetup. We open sourced the project at the end of the presentation.

License

The gascheduler library is licensed under the MIT license.

More Repositories

1

GA-SDK-UNITY

The GameAnalytics SDK for tracking events in Unity.
C
117
star
2

hyper

Erlang implementation of HyperLogLog
Erlang
95
star
3

GA-SDK-ROBLOX

Repository for GameAnalytics Roblox SDK
Lua
68
star
4

GA-SDK-UNREAL

A repository containing the GameAnalytics Unreal Engine 5 Plugin including documentation.
C++
54
star
5

panoramix

Apache Druid client for Elixir
Elixir
42
star
6

GA-SDK-GODOT

Official GameAnalytics Godot SDK repository
Objective-C
42
star
7

GA-SDK-CPP

Repository for GameAnalytics C++ SDK.
C
20
star
8

GA-SDK-JAVASCRIPT

Official repository for GameAnalytics JavaScript SDK
TypeScript
19
star
9

current

Erlang client for DynamoDB
Erlang
18
star
10

GA-SDK-IOS

Public repository for the native iOS SDK.
Objective-C
17
star
11

GA-SDK-DEFOLD

Repository for GameAnalytics Defold SDK
C++
14
star
12

GA-SDK-C-SHARP

Repository for GameAnalytics Mono / .Net 4.5 and UWP SDK. Written in C#.
C#
13
star
13

har_redbug

Trace an Erlang node and write HTTP requests to a file in HAR format
Erlang
11
star
14

GA-SDK-CONSTRUCT

Repository for GameAnalytics Construct SDK
8
star
15

godot-gameanalytics

Official GameAnalytics Godot SDK repository for NativeLib
Objective-C
8
star
16

GA-SDK-ANDROID

Public repository for the Android SDK.
C++
6
star
17

GA-SDK-AIR

Public repository for official GameAnalytics Adobe AIR SDK.
5
star
18

GA-SDK-GAMEMAKER

Repository for GameAnalytics GameMaker SDK
4
star
19

GA-SDK-COCOS2D

Repository for the GameAnalytics Cocos2d SDK.
C++
3
star
20

nativescript-gameanalytics

Repository for GameAnalytics NativeScript SDK.
TypeScript
3
star
21

python-style-guide

A guide on how to write good Python code at GA.
3
star
22

GA-SDK-XAMARIN

Xamarin SDK repository
3
star
23

github

Public repo containing github related stuff
Shell
1
star
24

GA-SDK-TVOS

Public repository for the native tvOS SDK.
Objective-C
1
star
25

GA-SDK-STENCYL

Repository for GameAnalytics Stencyl SDK
Haxe
1
star
26

GA-SDK-CORDOVA

Repository for GameAnalytics Cordova SDK for iOS and Android
Objective-C
1
star
27

GA-SDK-LUMBERYARD

Repository for GameAnalytics Lumberyard SDK
C++
1
star
28

meck

null
Erlang
1
star
29

ansible-carbon-relay-ng

Ansible role to install and configure carbon-relay-ng using supervisord
1
star