[erlang-questions] Custom supervisor
Paul Guyot
pguyot@REDACTED
Sat Jan 17 12:27:51 CET 2009
Le 17 janv. 09 à 10:52, Dominic Williams a écrit :
> Hi Paul,
>
> Paul Guyot a écrit :
> > [...]
>> Is there a more OTP-way to perform this, i.e. to track the death/
>> restarts of the children of a supervisor?
>
> In the OTP approach, you should not mix supervision with work. Your
> manager is doing work, so it should not be a supervisor as well.
>
> One solution would be for the manager to attach the workers as
> dynamic childs to its own supervisor. This would be if the number of
> workers is variable.
>
> If the number of workers is fixed, everyone (manager and workers)
> could be declared as fixed children in the same supervisor.
>
> Both of the above approaches are right if the restart strategies are
> the same for manager and workers, though, which is rarely the case.
> The "standard" solution in your kind of case is to have a top
> supervisor that supervises the manager and another supervisor. The
> sub-supervisor supervises all the workers. You'd probably need to
> have the workers register themselves with the manager when they
> start or restart.
Hello Dominic,
Thank you for your reply.
What you describe is what we did at first, i.e. a tree with a
manager_sup that has the manager and a worker_sup as its children, the
worker_sup having a simple_one_for_one strategy (we have a variable
number of workers). We abandoned this approach because the worker
needs to know when its started or restarted. Hence the idea of a
custom supervisor that would change a parameter to start_link whenever
the process is started or restarted. But maybe we outlook the standard
supervisor and there is a way to figure out if a worker is started or
restarted by the supervisor?
I also realize that having a supervisor doing some work is a very bad
idea as it implies that the workers are killed if the manager dies,
which might not be desirable.
Regards,
Paul
More information about the erlang-questions
mailing list