simple_one_for_one use case and docs

Garrett Smith g@REDACTED
Fri Jan 29 22:38:49 CET 2010


>From what I can tell, a simple_one_for_one supervisor is used to
simplify house keeping on a group of related processes.

- In init, provide a "prototype" child spec, which is used on calls to
start_child
- Use start_child to start a new child process using the child spec from init
- When the child process terminates, either restart it or remove it as
a child depending on restart policy:
  - temporary - remove it regardless of exit status
  - transient - restart it if abnormally terminated, remove if
normally terminated
  - permanent - always restart, never remove

This provides a "fire and forget" facility, so to speak, eliminating
the need to deal with messy links, etc. to cleanup/restart terminated
processes.

It seems that, if you use any of the other restart types (e.g.
one_for_one, etc.) you assume responsibility for deleting children if
you add them dynamically. If you want the "auto delete on terminate"
features of simple_one_for_one, you, well, need to use that supervisor
type.

Assuming I have this right, this took me a while to sort out.

I can't find this (I think very important) point in any of the
official Erlang docs. I think a line or two in the man docs for
supervisor would help clarify why someone would use
simple_one_for_one.

Garrett

P.S. Official docs are, IMO, quite good. This is just one feature that
I think is worth highlighting.


More information about the erlang-questions mailing list