summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@lshift.net>2008-11-26 17:28:08 +0000
committerSimon MacMullen <simon@lshift.net>2008-11-26 17:28:08 +0000
commite0b1254678da42f547deaa45bc70fdb2416b396a (patch)
tree7ca147236e20ea174b753a45b3dec711f613d58b /src
parentd3a787deadd0c1c1cb5fec74757dac939d3ce494 (diff)
downloadrabbitmq-server-git-e0b1254678da42f547deaa45bc70fdb2416b396a.tar.gz
Rearrange the startup so we only start rabbit_linux_memory if there is no memsup registered already, export some similar API to memsup so that we can configure stuff at runtime.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl2
-rw-r--r--src/rabbit_alarm.erl64
-rw-r--r--src/rabbit_linux_memory.erl9
3 files changed, 43 insertions, 32 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index cd2bda97ae..a33c5b7bcb 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -29,7 +29,7 @@
-export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]).
--export([start/2, stop/1, start_child/1]).
+-export([start/2, stop/1]).
-export([log_location/1]).
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl
index 1be0c6ab63..b3e629079b 100644
--- a/src/rabbit_alarm.erl
+++ b/src/rabbit_alarm.erl
@@ -51,42 +51,44 @@
start() ->
ok = alarm_handler:add_alarm_handler(?MODULE),
- case os:type() of
- {unix, linux} ->
- %% memsup doesn't take account of buffers or cache when considering
- %% "free" memory - therefore on Linux we can get memory alarms
- %% very easily without any pressure existing on memory at all.
- %% Therefore we need to use our own simple memory monitor
-
- rabbit:start_child(rabbit_linux_memory),
- ok;
- _ ->
- case whereis(memsup) of
- undefined ->
+ case whereis(memsup) of
+ undefined ->
+ case os:type() of
+ {unix, linux} ->
+ %% memsup doesn't take account of buffers or cache when considering
+ %% "free" memory - therefore on Linux we can get memory alarms
+ %% very easily without any pressure existing on memory at all.
+ %% Therefore we need to use our own simple memory monitor
+
+ supervisor:start_child(os_mon_sup, {memsup, {rabbit_linux_memory, start_link, []},
+ permanent, 2000, worker, [rabbit_linux_memory]}),
+ ok;
+ _ ->
%% Start memsup programmatically rather than via the rabbitmq-server
%% script. This is not quite the right thing to do as os_mon checks
%% to see if memsup is available before starting it, but as memsup
%% is available everywhere (even on VXWorks) it should be ok.
supervisor:start_child(os_mon_sup, {memsup, {memsup, start_link, []},
- permanent, 2000, worker, [memsup]});
- _ ->
- ok
- end,
-
- %% The default memsup check interval is 1 minute, which is way too
- %% long - rabbit can gobble up all memory in a matter of
- %% seconds. Unfortunately the memory_check_interval configuration
- %% parameter and memsup:set_check_interval/1 function only provide
- %% a granularity of minutes. So we have to peel off one layer of
- %% the API to get to the underlying layer which operates at the
- %% granularity of milliseconds.
- %%
- %% Note that the new setting will only take effect after the first
- %% check has completed, i.e. after one minute. So if rabbit eats
- %% all the memory within the first minute after startup then we
- %% are out of luck.
- ok = os_mon:call(memsup, {set_check_interval, ?MEMSUP_CHECK_INTERVAL},
- infinity)
+ permanent, 2000, worker, [memsup]}),
+
+
+ %% The default memsup check interval is 1 minute, which is way too
+ %% long - rabbit can gobble up all memory in a matter of
+ %% seconds. Unfortunately the memory_check_interval configuration
+ %% parameter and memsup:set_check_interval/1 function only provide
+ %% a granularity of minutes. So we have to peel off one layer of
+ %% the API to get to the underlying layer which operates at the
+ %% granularity of milliseconds.
+ %%
+ %% Note that the new setting will only take effect after the first
+ %% check has completed, i.e. after one minute. So if rabbit eats
+ %% all the memory within the first minute after startup then we
+ %% are out of luck.
+ ok = os_mon:call(memsup, {set_check_interval, ?MEMSUP_CHECK_INTERVAL},
+ infinity)
+ end;
+ _ ->
+ ok
end.
stop() ->
diff --git a/src/rabbit_linux_memory.erl b/src/rabbit_linux_memory.erl
index 5d9f52456d..47ba28deeb 100644
--- a/src/rabbit_linux_memory.erl
+++ b/src/rabbit_linux_memory.erl
@@ -52,6 +52,15 @@ init(_Args) ->
update() ->
gen_server:cast(?SERVER, do_update).
+%% Export the same API as the real memsup. Note that get_sysmem_high_watermark
+%% gives an int in the range 0 - 100, while set_sysmem_high_watermark
+%% takes a float in the range 0.0 - 1.0.
+handle_call(get_sysmem_high_watermark, _From, State) ->
+ {reply, trunc(100 * State#state.memory_fraction), State};
+
+handle_call({set_sysmem_high_watermark, Float}, _From, State) ->
+ {reply, ok, State#state{memory_fraction=Float}};
+
handle_call(_Request, _From, State) ->
{noreply, State}.