supervisor:restart_child/2 (throttling)

Pascal Brisset Pascal.Brisset@REDACTED
Sat Feb 24 08:09:16 CET 2001


Ulf Wiger writes:
 > The reason I even care is that I have re-written supervisor so that 
 > it is able to tell the child how many times it has restarted, and
 > by extension, whether it is starting for the first time, or whether
 > it is, for example, an escalated restart.

I would support some extensions to supervisor.erl too.

Suppose a supervised server tries to acquire some resource when it
starts, and crashes or terminates if it can't. If the resource is
unavailable, we don't really want the child to be shut down with
reached_max_restart_intensity.  The child can avoid this by waiting
for a fixed time on startup or before crashing, but then the
availability of the server would be less than optimal (if the child
has been running correctly for some time, we should try to restart it
immediately, and begin to delay the restarts only if it keeps crashing).

Letting the child know that it is having restart problems would
definitely helps. It would be even better if the supervisor itself
could be configured to throttle the child down, i.e. regulate its
restart frequency with some kind of exponential back-off.

-- Pascal

--- supervisor.erl Thu Dec 14 09:25:59 2000
+++ rsupervisor.erl     Sun Jan 21 20:51:28 2001
@@ -445,9 +462,11 @@
        {ok, NState} ->
            restart(NState#state.strategy, Child, NState);
        {terminate, NState} ->
-           report_error(shutdown, reached_max_restart_intensity,
+           report_error(regulate, restart_delayed,
                         Child, State#state.name),
-           {shutdown, remove_child(Child, NState)}
+           %% We should use a smarter delay here, and sleep asynchronously.
+           receive after State#state.period * 1000 -> ok end,
+           restart(Child, State)
     end.




More information about the erlang-questions mailing list