aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/supervisor_deadlock.erl
diff options
context:
space:
mode:
authorRory Byrne <[email protected]>2015-05-28 19:41:25 +0100
committerSiri Hansen <[email protected]>2016-02-03 12:14:11 +0100
commit264a5e804d6e23bf6c6916887669760cbf243caa (patch)
tree36c811242327adf2da0cde5003ac486a75f70602 /lib/stdlib/test/supervisor_deadlock.erl
parent4422cb32637a341eac2dc03172e4aa859be67f34 (diff)
downloadotp-264a5e804d6e23bf6c6916887669760cbf243caa.tar.gz
otp-264a5e804d6e23bf6c6916887669760cbf243caa.tar.bz2
otp-264a5e804d6e23bf6c6916887669760cbf243caa.zip
Speed up supervisor:count_children/1; simple_one_for_one
Speed up supervisor:count_children/1 for simple_one_for_one supervisors. This is achieved by avoiding looping through all the child process and verifying that each one is alive. For a supervisor with 100,000 'temporary' children the count-time will drop from approx 25ms to about 0.005ms. For a supervisor with 100,000 'permanent' or 'transient' children the count-time will drop from approx 30ms to about 0.005ms. This avoids having the supervisor block for an extended period while the count takes place. Under normal circumstances the accuracy of the result should also improve since the duration is too short for many processes to die during the count.
Diffstat (limited to 'lib/stdlib/test/supervisor_deadlock.erl')
-rw-r--r--lib/stdlib/test/supervisor_deadlock.erl14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/stdlib/test/supervisor_deadlock.erl b/lib/stdlib/test/supervisor_deadlock.erl
index 288547a972..8d3d1c6f30 100644
--- a/lib/stdlib/test/supervisor_deadlock.erl
+++ b/lib/stdlib/test/supervisor_deadlock.erl
@@ -11,9 +11,11 @@ init([child]) ->
%% terminates immediately
{ok, []};
[{fail_start, true}] ->
- %% Restart frequency is MaxR=8, MaxT=10, so this will
- %% ensure that restart intensity is not reached -> restart
- %% loop
+ %% A restart frequency of MaxR=8, MaxT=10 should ensure
+ %% that restart intensity is not reached -> restart loop.
+ %% (Note that if we use simple_one_for_one, and start
+ %% 'many' child instances, the restart frequency must be
+ %% ajusted accordingly.)
timer:sleep(2000), % NOTE: this could be a gen_server call timeout
{stop, error}
@@ -41,5 +43,11 @@ code_change(_OldVsn, State, _Extra) ->
start_child() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [child], []).
+start_child_noreg() ->
+ gen_server:start_link(?MODULE, [child], []).
+
restart_child() ->
gen_server:cast(supervisor_deadlock, restart).
+
+restart_child(Pid) ->
+ gen_server:cast(Pid, restart).