diff options
author | Jay Nelson <[email protected]> | 2010-01-25 11:01:32 -0800 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-02-10 17:14:28 +0100 |
commit | 1686757b304b66050f54db8e0ce5ab758bde96af (patch) | |
tree | 4b23dd691ff970e43bc5bfb6dc87941facee621c /lib/stdlib/doc | |
parent | ada6afd00530d6569c41741cfd9d63311ff60f25 (diff) | |
download | otp-1686757b304b66050f54db8e0ce5ab758bde96af.tar.gz otp-1686757b304b66050f54db8e0ce5ab758bde96af.tar.bz2 otp-1686757b304b66050f54db8e0ce5ab758bde96af.zip |
Add count_children/1 to supervisor.erl to determine the number of
children being managed without the memory impact of which_children/1
The function which_children/1 returns a list of the child processes
currently being supervised, but it has the penalty of creating a new
list thereby consuming more memory. In low memory situations it is
often desirable to know which supervisor may have generated many
processes, but the act of discovering the culprit should not cause the
node to crash (or worse a different node if the kernel kills one
randomly). The new function count_children/1 can give an indication
of which supervisor is taxing resources the most without adding to the
burden. Rather than creating a new list, it walks the supervisor's
internal children structure using an accumulator function so that any
used memory can be incrementally collected yet the resulting count can
still be obtained.
The return result of count_children/1 is a property list of counts
containing:
- {specs, Total_Num_Child_Specs}
- {active, Num_Active_Child_Processes_Of_Supervisor_Or_Worker_Type}
- {supervisors, Num_Supervisor_Type_Children_Including_Dead_Processes}
- {workers, Num_Worker_Type_Children_Including_Dead_Processes}
This patch was made in response to mailing list discussions of the
problem diagnosing heavily taxed production systems. I cannot find
the original request, but http://www.erlang.org/cgi-bin/ezmlm-cgi/4/35060
is my original post of the patch.
Diffstat (limited to 'lib/stdlib/doc')
-rw-r--r-- | lib/stdlib/doc/src/supervisor.xml | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/stdlib/doc/src/supervisor.xml b/lib/stdlib/doc/src/supervisor.xml index adf9d24eae..fb2ec9ba67 100644 --- a/lib/stdlib/doc/src/supervisor.xml +++ b/lib/stdlib/doc/src/supervisor.xml @@ -402,9 +402,12 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules} <v> Module = atom()</v> </type> <desc> - <p>Returns a list with information about all child + <p>Returns a newly created list with information about all child specifications and child processes belonging to the supervisor <c>SupRef</c>.</p> + <p>Note that calling this function when supervising a large + number of children under low memory conditions can cause an + out of memory exception.</p> <p>See <c>start_child/2</c> for a description of <c>SupRef</c>.</p> <p>The information given for each child specification/process is:</p> @@ -428,6 +431,39 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules} </desc> </func> <func> + <name>count_children(SupRef) -> PropListOfCounts</name> + <fsummary>Return counts for the number of childspecs, active children, supervisors and workers.</fsummary> + <type> + <v>SupRef = Name | {Name,Node} | {global,Name} | pid()</v> + <v> Name = Node = atom()</v> + <v>PropListOfCounts = [{specs, ChildSpecCount}, {active, ActiveProcessCount}, {supervisors, ChildSupervisorCount}, {workers, ChildWorkerCount}]</v> + </type> + <desc> + <p>Returns a property list (see <c>proplists</c>) containing the + counts for each of the following elements of the supervisor's + child specifications and managed processes:</p> + <list type="bulleted"> + <item> + <p><c>specs</c> - the total count of children, dead or alive.</p> + </item> + <item> + <p><c>active</c> - the count of all actively running child processes + managed by this supervisor.</p> + </item> + <item> + <p><c>supervisors</c> - the count of all children marked as + child_type = supervisor in the spec list, whether or not the + child process is still alive.</p> + </item> + <item> + <p><c>workers</c> - the count of all children marked as + child_type = worker in the spec list, whether or not the child + process is still alive.</p> + </item> + </list> + </desc> + </func> + <func> <name>check_childspecs([ChildSpec]) -> Result</name> <fsummary>Check if children specifications are syntactically correct.</fsummary> <type> |