Questions tagged [erlang-supervisor]

Supervisors are one of the core things that make Erlang/OTP what it is. An active OTP application consists of one or more processes that do the work. Those processes are started indirectly by supervisors, which are responsible for supervising them and restarting them if necessary. A running application is essentially a tree of processes, both supervisors and workers, where the root of the tree is the root supervisor.

"Supervisor" is a concept in the Erlang programming language. It refers to a process whose role is to monitor other processes, and restart them if they crash.

The supervisor is responsible for starting, stopping and monitoring its child processes. The basic idea of a supervisor is that it should keep its child processes alive by restarting them when necessary.

The children of a supervisor is defined as a list of child specifications. When the supervisor is started, the child processes are started in order from left to right according to this list. When the supervisor terminates, it first terminates its child processes in reversed start order, from right to left.

205 questions
16
votes
4 answers

What's the benefit of registering name using {:via, module, term} in GenServer.start_link/3?

In GenServer.start_link/3 I can register a name locally using an atom for a process like this: defmodule Worker do use GenServer def start_link do GenServer.start_link(__MODULE__, nil, name: :worker) end end Then I can start a supervisor…
sbs
  • 4,102
  • 5
  • 40
  • 54
14
votes
2 answers

Erlang: supervisor(3), adding a child process

Where can I find example on how to add dynamic child processes to an existing supervisor (simple_one_for_one restart strategy) ?
0xAX
  • 20,957
  • 26
  • 117
  • 206
12
votes
2 answers

What's the best way to run a gen_server on all nodes in an Erlang cluster?

I'm building a monitoring tool in Erlang. When run on a cluster, it should run a set of data collection functions on all nodes and record that data using RRD on a single "recorder" node. The current version has a supervisor running on the master…
afternoon
  • 1,285
  • 16
  • 25
12
votes
1 answer

Elixir: Difference between Supervisor, GenServer and Application

I was practicing with this example. https://github.com/kwmiebach/how-to-elixir-supervisor I followed the instruction and got the idea of how it works, but I can't understand how Supervisor, GenServer and Application are different to each other…
HelloWorld
  • 973
  • 2
  • 9
  • 23
11
votes
3 answers

Erlang: Who supervises the supervisor?

In all Erlang supervisor examples I have seen yet, there usually is a "master" supervisor who supervises the whole tree (or at least is the root node in the supervisor tree). What if the "master"-supervisor breaks? How should the "master"-supervisor…
Daniel
  • 20,420
  • 10
  • 92
  • 149
11
votes
2 answers

Erlang supervisor dynamic change to restart intensity

My question is, can one modify the restart intensity thresholds of an already running supervisor, apart from in a release upgrade scenario, and if so, how? It's never come up before, but running a supervisor with initially no children, so that…
Michael
  • 3,639
  • 14
  • 29
10
votes
1 answer

simple_one_for_one start_child() returns already_started

I have a supervisor which should start simple_one_for_one workers. When I call start_child() for the first time, everything goes excellent. But, when I do it the second time, I get {error,{already_started,<0.71.0>}}. Why would simple_one_for_one…
dijxtra
  • 2,681
  • 4
  • 25
  • 37
10
votes
3 answers

erlang OTP Supervisor crashing

I'm working through the Erlang documentation, trying to understand the basics of setting up an OTP gen_server and supervisor. Whenever my gen_server crashes, my supervisor crashes as well. In fact, whenever I have an error on the command line, my…
drfloob
  • 3,154
  • 1
  • 24
  • 31
10
votes
1 answer

My supervisor crashes when I try to start it from eshell?

I'm very new to OTP, I'm trying to create simple example to understand supervisor behaviour: Here is simple increment server -module( inc_serv ). -behaviour( gen_server ). -export( [ start/0, inc/1, stop/0 ] ). -export( [ init/1, handle_call/3,…
stemm
  • 5,960
  • 2
  • 34
  • 64
9
votes
2 answers

Erlang supervisor restart interval

I have a supervisor with one_for_one restart strategy. Is it possible to set some time interval between child process restarting? For example, the remote db crushed and I want to wait 10 seconds between restore connection attempts.
kolchanov
  • 2,018
  • 2
  • 14
  • 32
8
votes
2 answers

How can I restore process state after a crash?

What's a good way to persist state when restarting a crashed process? I have a supervisor in an OTP application what watches several "subsystem" gen_servers. For example, one is a "weather" subsystem that generates a new weather state every 15…
Kyle K
8
votes
2 answers

Erlang supervisor: how to check if all the workers have replied

I have a supervisor with N worker processes. As usual the supervisor can send a message to a worker process and there is a handle_cast that sends a reply from a worker to the supervisor. How can I check that exactly all N workers have replied to the…
skanatek
  • 5,133
  • 3
  • 47
  • 75
8
votes
1 answer

Erlang OTP supervising Java application

I have recently become familiar with Erlang/OTP technology and I would like to apply it to monitor and supervise Java applications in terms of: detecting their availability starting and stopping them In other words I would like Java applications…
gregorej
  • 571
  • 1
  • 5
  • 18
8
votes
2 answers

How to find the supervisor of an OTP process?

Are there functions which would allow an OTP process to find the pid of its supervisor?
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
8
votes
1 answer

Can an OTP supervisor monitor a process on a remote node?

I'd like to use erlang's OTP supervisor in a distributed application I'm building. But I'm having trouble figuring out how a supervisor of this kind can monitor a process running on a remote Node. Unlike erlang's start_link function, start_child has…
Brinley
  • 591
  • 2
  • 14
  • 26
1
2 3
13 14