Supervisor

Supervisors are one of the most important features of OTP. They monitor other processes and take action if anything goes wrong, restarting the failed process or possibly escalating the problem to a higher level. Layering supervisors into supervision trees allows you to create highly fault-tolerant systems. (Logan, Merritt, and Carlsson 2010)

The Supervision Tree

A supervision tree is a tree of processes. The upper processes (supervisors) in the tree monitor the lower processes (workers) in the tree and restart the lower processes if they fail. (Armstrong 2013, 398)

There are two types of supervision trees:

one_for_one
If one process crashes, it is restarted.
erlang_supervisor_o4o.png
one_for_all
If one process crashes, all others are terminated and then restarted as well.
erlang_supervisor_o4a.png

Independent of what the monited application does, a supervisor works is always the same can be divided into two categories:

  • A generic part that deals with starting, monitoring and restarting child processes.
  • A specific part that consists of the specification of how the children are supposed to be started and restarted.

Robust Systems

In Erlang, you build robust systems by layering. Using processes, you create a tree in which the leaves consist of the application layer that handles the operational tasks while the interior nodes monitor the leaves and other nodes below them, (…). Processes at any level will trap errors occurring at a level immediately below them. A process whose only task is to supervise children—in our case the nodes of the tree—is called a supervisor. A leaf process performing operational tasks is called a worker. When we refer to child processes, we mean both supervisors and workers belonging to a particular supervisor.

(Cesarini and Thompson 2009, 148)

References:

Armstrong, Joe. 2013. “Programming Erlang: Software for a Concurrent World.”
Cesarini, Francesco, and Simon Thompson. 2009. Erlang Programming: A Concurrent Approach to Software Development. O’Reilly Media, Inc.
Logan, Martin, Eric Merritt, and Richard Carlsson. 2010. Erlang and Otp in Action. Manning Publications Co.

Backlinks: