diff options
author | José Valim <[email protected]> | 2016-03-31 10:48:11 +0200 |
---|---|---|
committer | José Valim <[email protected]> | 2016-03-31 11:02:34 +0200 |
commit | 44d5789619c70863af918ee5e2bdd7d411e68e80 (patch) | |
tree | 466c3fda593bdb92291a8782e7b575ddbce14915 /lib/stdlib/src/supervisor.erl | |
parent | 10a218b37324fd94ddbfe5568554de263492c82c (diff) | |
download | otp-44d5789619c70863af918ee5e2bdd7d411e68e80.tar.gz otp-44d5789619c70863af918ee5e2bdd7d411e68e80.tar.bz2 otp-44d5789619c70863af918ee5e2bdd7d411e68e80.zip |
Avoid potential timer bottleneck on supervisor restart
Prior to this patch, when the supervisor was unable to
restart a child, it used the timer process to execute
a function later on, allowing other messages in the
supervisor queue to be consumed.
This patch keeps the same idea but bypasses the timer
process by directly sending a message to the supervisor
process itself.
Diffstat (limited to 'lib/stdlib/src/supervisor.erl')
-rw-r--r-- | lib/stdlib/src/supervisor.erl | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl index 0400c845ab..9d783af82a 100644 --- a/lib/stdlib/src/supervisor.erl +++ b/lib/stdlib/src/supervisor.erl @@ -246,7 +246,7 @@ check_childspecs(ChildSpecs) when is_list(ChildSpecs) -> check_childspecs(X) -> {error, {badarg, X}}. %%%----------------------------------------------------------------- -%%% Called by timer:apply_after from restart/2 +%%% Called by restart/2 -spec try_again_restart(SupRef, Child) -> ok when SupRef :: sup_ref(), Child :: child_id() | pid(). @@ -571,8 +571,8 @@ count_child(#child{pid = Pid, child_type = supervisor}, end. -%%% If a restart attempt failed, this message is sent via -%%% timer:apply_after(0,...) in order to give gen_server the chance to +%%% If a restart attempt failed, this message is cast +%%% from restart/2 in order to give gen_server the chance to %%% check it's inbox before trying again. -spec handle_cast({try_again_restart, child_id() | pid()}, state()) -> {'noreply', state()} | {stop, shutdown, state()}. @@ -790,16 +790,10 @@ restart(Child, State) -> Id = if ?is_simple(State) -> Child#child.pid; true -> Child#child.name end, - {ok, _TRef} = timer:apply_after(0, - ?MODULE, - try_again_restart, - [self(),Id]), + ok = try_again_restart(self(), Id), {ok,NState2}; {try_again, NState2, #child{name=ChName}} -> - {ok, _TRef} = timer:apply_after(0, - ?MODULE, - try_again_restart, - [self(),ChName]), + ok = try_again_restart(self(), ChName), {ok,NState2}; Other -> Other |