diff options
author | Emile Joubert <emile@rabbitmq.com> | 2011-08-31 09:51:48 +0100 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2011-08-31 09:51:48 +0100 |
commit | 4f515599a6ee73162665e44438cd7930bc27fd97 (patch) | |
tree | 290f596c5ac31b0e1c039850299326ecbb6a114d | |
parent | 2873f3d8c968ba1630e4f601ee7b8a3cfb101527 (diff) | |
parent | 2e10ce2b7c885dcf65b5014f954fcf7fc3598f04 (diff) | |
download | rabbitmq-server-4f515599a6ee73162665e44438cd7930bc27fd97.tar.gz |
Merged default into bug24323
-rw-r--r-- | docs/rabbitmqctl.1.xml | 95 | ||||
-rw-r--r-- | src/rabbit.erl | 8 | ||||
-rw-r--r-- | src/rabbit_control.erl | 5 | ||||
-rw-r--r-- | src/vm_memory_monitor.erl | 54 |
4 files changed, 96 insertions, 66 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 3291c44d..29d9032b 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -390,44 +390,6 @@ </refsect2> <refsect2> - <title>Closing individual connections</title> - - <variablelist> - <varlistentry> - <term><cmdsynopsis><command>close_connection</command> <arg choice="req"><replaceable>connectionpid</replaceable></arg> <arg choice="req"><replaceable>explanation</replaceable></arg></cmdsynopsis></term> - <listitem> - <variablelist> - <varlistentry> - <term>connectionpid</term> - <listitem><para>Id of the Erlang process associated with the connection to close.</para></listitem> - </varlistentry> - <varlistentry> - <term>explanation</term> - <listitem><para>Explanation string.</para></listitem> - </varlistentry> - </variablelist> - <para> - Instruct the broker to close the connection associated - with the Erlang process id <option>connectionpid</option> (see also the - <link linkend="list_connections"><command>list_connections</command></link> - command), passing the <option>explanation</option> string to the - connected client as part of the AMQP connection shutdown - protocol. - </para> - <para role="example-prefix">For example:</para> - <screen role="example">rabbitmqctl close_connection "<rabbit@tanto.4262.0>" "go away"</screen> - <para role="example"> - This command instructs the RabbitMQ broker to close the - connection associated with the Erlang process - id <command><rabbit@tanto.4262.0></command>, passing the - explanation <command>go away</command> to the connected client. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect2> - - <refsect2> <title>User management</title> <para> Note that <command>rabbitmqctl</command> manages the RabbitMQ @@ -1306,9 +1268,14 @@ <para> Displays broker status information such as the running applications on the current Erlang node, RabbitMQ and - Erlang versions and OS name. (See - the <command>cluster_status</command> command to find - out which nodes are clustered and running.) + Erlang versions, OS name and memory statistics. + In this context <varname>vm_memory_high_watermark</varname> + indicates the fraction of memory at which flow control is + triggered. <varname>vm_memory_limit</varname> refers to the + absolute memory threshhold at which flow control is triggered. + The unit of this number and those listed in the <varname>memory</varname> + section is bytes. (See the <command>cluster_status</command> + command to find out which nodes are clustered and running.) </para> <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl status</screen> @@ -1352,9 +1319,40 @@ </refsect2> <refsect2> - <title>Message Tracing</title> + <title>Miscellaneous</title> <variablelist> <varlistentry> + <term><cmdsynopsis><command>close_connection</command> <arg choice="req"><replaceable>connectionpid</replaceable></arg> <arg choice="req"><replaceable>explanation</replaceable></arg></cmdsynopsis></term> + <listitem> + <variablelist> + <varlistentry> + <term>connectionpid</term> + <listitem><para>Id of the Erlang process associated with the connection to close.</para></listitem> + </varlistentry> + <varlistentry> + <term>explanation</term> + <listitem><para>Explanation string.</para></listitem> + </varlistentry> + </variablelist> + <para> + Instruct the broker to close the connection associated + with the Erlang process id <option>connectionpid</option> (see also the + <link linkend="list_connections"><command>list_connections</command></link> + command), passing the <option>explanation</option> string to the + connected client as part of the AMQP connection shutdown + protocol. + </para> + <para role="example-prefix">For example:</para> + <screen role="example">rabbitmqctl close_connection "<rabbit@tanto.4262.0>" "go away"</screen> + <para role="example"> + This command instructs the RabbitMQ broker to close the + connection associated with the Erlang process + id <command><rabbit@tanto.4262.0></command>, passing the + explanation <command>go away</command> to the connected client. + </para> + </listitem> + </varlistentry> + <varlistentry> <term><cmdsynopsis><command>trace_on</command> <arg choice="opt">-p <replaceable>vhost</replaceable></arg></cmdsynopsis></term> <listitem> <variablelist> @@ -1383,7 +1381,18 @@ </para> </listitem> </varlistentry> - + <varlistentry> + <term><cmdsynopsis><command>set_vm_memory_high_watermark</command> <arg choice="req"><replaceable>fraction</replaceable></arg></cmdsynopsis></term> + <listitem> + <variablelist> + <varlistentry> + <term>fraction</term> + <listitem><para>The new memory threshhold fraction at which flow control is triggered, as a + floating point number between 0.0 and 1.0 with a mandatory fractional part.</para></listitem> + </varlistentry> + </variablelist> + </listitem> + </varlistentry> </variablelist> </refsect2> </refsect1> diff --git a/src/rabbit.erl b/src/rabbit.erl index b8dbccc7..2403d027 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -239,7 +239,13 @@ status() -> {running_applications, application:which_applications(infinity)}, {os, os:type()}, {erlang_version, erlang:system_info(system_version)}, - {memory, erlang:memory()}]. + {memory, erlang:memory()}] ++ + case is_running() of + true -> [{vm_memory_high_watermark, + vm_memory_monitor:get_vm_memory_high_watermark()}, + {vm_memory_limit, vm_memory_monitor:get_memory_limit()}]; + false -> [] + end. is_running() -> is_running(node()). diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 1163ae9d..9034c81f 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -321,6 +321,11 @@ action(trace_off, Node, [], Opts, Inform) -> Inform("Stopping tracing for vhost ~p", [VHost]), rpc_call(Node, rabbit_trace, stop, [list_to_binary(VHost)]); +action(set_vm_memory_high_watermark, Node, [Arg], _Opts, Inform) -> + Frac = list_to_float("0" ++ Arg), + Inform("Setting memory threshhold on ~p to ~p", [Node, Frac]), + rpc_call(Node, vm_memory_monitor, set_vm_memory_high_watermark, [Frac]); + action(set_permissions, Node, [Username, CPerm, WPerm, RPerm], Opts, Inform) -> VHost = proplists:get_value(?VHOST_OPT, Opts), Inform("Setting permissions for user ~p in vhost ~p", [Username, VHost]), diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl index fb2fa267..3b955914 100644 --- a/src/vm_memory_monitor.erl +++ b/src/vm_memory_monitor.erl @@ -40,6 +40,7 @@ -define(SERVER, ?MODULE). -define(DEFAULT_MEMORY_CHECK_INTERVAL, 1000). +-define(ONE_MB, 1048576). %% For an unknown OS, we assume that we have 1GB of memory. It'll be %% wrong. Scale by vm_memory_high_watermark in configuration to get a @@ -106,35 +107,20 @@ start_link(Args) -> gen_server:start_link({local, ?SERVER}, ?MODULE, [Args], []). init([MemFraction]) -> - TotalMemory = - case get_total_memory() of - unknown -> - error_logger:warning_msg( - "Unknown total memory size for your OS ~p. " - "Assuming memory size is ~pMB.~n", - [os:type(), trunc(?MEMORY_SIZE_FOR_UNKNOWN_OS/1048576)]), - ?MEMORY_SIZE_FOR_UNKNOWN_OS; - M -> M - end, - MemLimit = get_mem_limit(MemFraction, TotalMemory), - error_logger:info_msg("Memory limit set to ~pMB.~n", - [trunc(MemLimit/1048576)]), TRef = start_timer(?DEFAULT_MEMORY_CHECK_INTERVAL), - State = #state { total_memory = TotalMemory, - memory_limit = MemLimit, - timeout = ?DEFAULT_MEMORY_CHECK_INTERVAL, + State = #state { timeout = ?DEFAULT_MEMORY_CHECK_INTERVAL, timer = TRef, alarmed = false}, - {ok, internal_update(State)}. + {ok, internal_update(set_mem_limits(State, MemFraction))}. handle_call(get_vm_memory_high_watermark, _From, State) -> {reply, State#state.memory_limit / State#state.total_memory, State}; handle_call({set_vm_memory_high_watermark, MemFraction}, _From, State) -> - MemLimit = get_mem_limit(MemFraction, State#state.total_memory), + State1 = set_mem_limits(State, MemFraction), error_logger:info_msg("Memory alarm changed to ~p, ~p bytes.~n", - [MemFraction, MemLimit]), - {reply, ok, State#state{memory_limit = MemLimit}}; + [MemFraction, State1#state.memory_limit]), + {reply, ok, State1}; handle_call(get_check_interval, _From, State) -> {reply, State#state.timeout, State}; @@ -168,6 +154,30 @@ code_change(_OldVsn, State, _Extra) -> %% Server Internals %%---------------------------------------------------------------------------- +set_mem_limits(State, MemFraction) -> + TotalMemory = + case get_total_memory() of + unknown -> + case State of + #state { total_memory = undefined, + memory_limit = undefined } -> + error_logger:warning_msg( + "Unknown total memory size for your OS ~p. " + "Assuming memory size is ~pMB.~n", + [os:type(), + trunc(?MEMORY_SIZE_FOR_UNKNOWN_OS/?ONE_MB)]); + _ -> + ok + end, + ?MEMORY_SIZE_FOR_UNKNOWN_OS; + M -> M + end, + MemLim = get_mem_limit(MemFraction, TotalMemory), + error_logger:info_msg("Memory limit set to ~pMB of ~pMB total.~n", + [trunc(MemLim/?ONE_MB), trunc(TotalMemory/?ONE_MB)]), + State #state { total_memory = TotalMemory, + memory_limit = MemLim }. + internal_update(State = #state { memory_limit = MemLimit, alarmed = Alarmed}) -> MemUsed = erlang:memory(total), @@ -322,9 +332,9 @@ parse_line_sunos(Line) -> [Value1 | UnitsRest] = string:tokens(RHS, " "), Value2 = case UnitsRest of ["Gigabytes"] -> - list_to_integer(Value1) * 1024 * 1024 * 1024; + list_to_integer(Value1) * ?ONE_MB * 1024; ["Megabytes"] -> - list_to_integer(Value1) * 1024 * 1024; + list_to_integer(Value1) * ?ONE_MB; ["Kilobytes"] -> list_to_integer(Value1) * 1024; _ -> |