[erlang-patches] allow use of proplists in supervisor start specs

Siri Hansen erlangsiri@REDACTED
Mon Jun 30 15:14:24 CEST 2014


Hello!

Taking the idea from this patch, I have now implemented a similar solution
using maps instead of proplists. This is planned to be included in OTP 18.

The reason for choosing maps is mostly the simplicity compared to
proplists. We do not expect supervisor to be used with earlier releases of
OTP, so we see no problem in introducing maps here.

After some discussions we have chosen slightly different default values
than in the original patch. First we discussed whether or not to have
default values at all, but decided to have it in order to somehow lower the
start barrier and make it easy to get "something" running.

Next we found that it would be very difficult to give default values that
in general are "good", so we decided to use values that are "extreme" in
one direction or the other - hopefully forcing the user to really think
about which values to set instead of just settling with the defaults. So
the defaults are not so much for the final product as for the first
prototype.

Default values are as follows:

Supervisor flags:

Strategy: one_for_one.
Just pick one - 'one_for_one' is most used in OTP so we chose that.

Intensity: 0.
Better too few restarts by default than too many, in order to avoid scaling
to extreme amounts of restarts if the depth of the supervisor tree grows.

Period: 1.
Since Intensity is by default 0, the Period will really not matter but
setting a large value as default could potentially be a problem if the
intensity is changed.

Child specs:

Restart: permanent.
Just pick one - 'permanent' is fairly common.

Shutdown: brutal_kill.
We want to avoid doing the same mistake as the 5 seconds default for
gen_server:call, so we chose between 'brutal_kill' and 'inifinity', then
settled for 'brutal_kill' since 'infinity' can cause bigger problems.

Type: worker.
Just pick one - we believe that 'worker' is most common.

Modules: [M].
where M comes from the child's start {M,F,A}.

Any comments on this?

Regards
/siri


2012-01-03 22:11 GMT+01:00 Richard Carlsson <carlsson.richard@REDACTED>:

> The formats of the supervisor flags (the 3-tuple {one_for_one, Restarts,
> Time}) and the child specifications (6-tuples {name, etc., etc.}) are
> annoyingly hard both to read and write. This patch makes it possible to
> pass lists of options instead, and sets useful defaults for most fields.
> This also opens for the possibility to add more flags both to supervisors
> and children in the future.
>
>   git fetch git://github.com/richcarl/otp.git proplist-child-spec
>
> For example:
>
>   init()
>      SupFlags = [{period,10}],
>      Child = [{name, foo}, {start, {M,F,A}}]
>      {ok, {SupFlags, [Child]}}.
>
> This gets you a one-for-one supervisor with a particular restart time
> period, and a single child with default behaviour. The name and start
> options are required.
>
> The supervisor flag defaults are:
>
>     strategy = one_for_one
>     intensity = 10
>     period = 30
>
> I.e., one-for-one supervision and at most 10 restarts in the last 30
> seconds. This restart frequency seems like a useful default; let me know if
> you think some other numbers would be significantly better.
>
> The child spec defaults are:
>     restart_type = permanent
>     shutdown = 2000
>     child_type = worker
>     modules = [M], where M is the module in the start MFA
>
> Finally, there is a new function supervisor:get_childspec(Sup, Child)
> which can be used to get the full child specification (as a list) needed to
> restart the same child or another child like it.
>
> Note that the documentation has not been updated as part of this patch.
>
>   /Richard
> _______________________________________________
> erlang-patches mailing list
> erlang-patches@REDACTED
> http://erlang.org/mailman/listinfo/erlang-patches
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20140630/c6cdf95e/attachment.htm>


More information about the erlang-patches mailing list