[erlang-patches] Supervisor improvements
Christopher Faulet
christopher.faulet@REDACTED
Thu Sep 8 15:16:27 CEST 2011
Le 08/09/2011 12:24, Siri Hansen a écrit :
> Hi Christopher!
>
> Thanks for you contribution! Could you please give some background
> information regarding the use of these new features? In which situations
> do you find them useful?
>
Yes, sure.
Set the shutdown strategy of a supervisor to infinity when child process
is a worker is useful when its cleanup _MUST_ be done or when it _MUST_
reply to a request in progress.
For example, If you have a process that read its internal state in a
database when 'Module:init/1' is called and write it in
'Module:terminate/2'. It's hard to set an upper bound timeout here. And,
for some external reasons, it may be slow. In all case, you want to be
sure that the supervisor won't kill the process too early. Here, an
infinite timeout is a good solution. It exists some workarounds, but not
usable in all cases. I think that killing a worker after a timeout is
highly application-dependent. It's a shame to force developers to use
it. My approach is to let the choice.
The problem with simple_one_for_one supervisors has already been
explained on erlang-questions [1]. A nice workaround is used in Agner
[2]. IMHO, it's a breach of promises made by the supervisor behavior.
its purpose is to start, stop and monitor its child processes,
restarting them when necessary. There is no reason to deal with dynamic
child processes in a different way than other child processes. this can
be seen as a lack of consistency.
In fact, my patches try to solve 2 sides of the same problem: How to
control the shutdown of a worker in a supervision tree, no matter what
happens.
[1] http://erlang.org/pipermail/erlang-questions/2011-February/056228.html
[2] https://github.com/agner/agner/blob/master/src/agner_app.erl
--
Christopher Faulet
http://www.yakaz.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20110908/cedfaf86/attachment.bin>
More information about the erlang-patches
mailing list