Supervision hierarchies

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

I feel like this is the core idea of Erlang:

Recall that at the beginning of this chapter we talked about the idea of a
hierarchy of tasks. The basic idea is:

1. Try to perform a task.

2. If you cannot perform the task, then try to perform a simpler task.

To each task we associate an supervisor process—the supervisor will assign a worker to try and achieve the goals implied by the task. If the worker process fails with a non-normal exit then the supervisor will assume that the task has failed and will initiate some error recovery procedure. The error recovery procedure might be to restart the worker or failing this try to do something simpler.

Supervisors and workers are arranged into hierarchical trees, according
to the following:

1. Supervision trees are trees of Supervisors.

2. Supervisors monitor Workers and Supervisors.

3. Workers are instances of Behaviours.

4. Behaviours are parameterised by Well-behaved functions.

5. Well-behaved functions raise exceptions when errors occur.

Where:

Supervision trees are hierarchical trees of supervisors. Each node in the tree is responsible for monitoring errors in its child nodes.

• Supervisors are processes which monitor other processes in the system. The things that are monitored are either supervisors or workers. Supervisors must be able to detect exceptions generated by the things they are monitoring, and be able to start, stop and restart the things they are monitoring.

• Workers are processes which perform tasks.

If a worker process terminates with a non-normal exit (see page 74) the supervisor will assume that an error has occurred and will take action to recover from the error. Workers in our model are not arbitrary processes, but are instances of one of a small number of generic processes (called behaviours).

• Behaviours are generic processes whose operation is entirely characterised by a small number of callback functions. These functions must be instances of well-behaved functions.

Post external references

  1. 1
    http://www.erlang.org/download/armstrong_thesis_2003.pdf
Source