diff options
author | Simon MacMullen <simon@lshift.net> | 2008-11-27 14:09:59 +0000 |
---|---|---|
committer | Simon MacMullen <simon@lshift.net> | 2008-11-27 14:09:59 +0000 |
commit | f725778cfdf50f522fbabcd44ca448480df81e24 (patch) | |
tree | caff6994b4c7c5093dddacbbaf8387c7573887bb | |
parent | 21676b518340f310320e6c511b2d5faea1f43067 (diff) | |
download | rabbitmq-server-f725778cfdf50f522fbabcd44ca448480df81e24.tar.gz |
Support get / set_check_interval and simplify starting.
-rw-r--r-- | src/rabbit_alarm.erl | 45 | ||||
-rw-r--r-- | src/rabbit_memsup_linux.erl | 25 |
2 files changed, 42 insertions, 28 deletions
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl index 5a19aca0..f66aefd0 100644 --- a/src/rabbit_alarm.erl +++ b/src/rabbit_alarm.erl @@ -74,33 +74,32 @@ start() -> %% we can add our alarm_handler before memsup is %% running, thus ensuring that we notice memory %% alarms that go off on startup. - {ok, _} = start_memsup(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) + {ok, _} = start_memsup(memsup) end, ok; _ -> ok - end. + 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). stop() -> ok = alarm_handler:delete_alarm_handler(?MODULE). diff --git a/src/rabbit_memsup_linux.erl b/src/rabbit_memsup_linux.erl index c9ff1c91..5e998dce 100644 --- a/src/rabbit_memsup_linux.erl +++ b/src/rabbit_memsup_linux.erl @@ -36,9 +36,9 @@ -define(SERVER, memsup). %% must be the same as the standard memsup --define(MEMORY_CHECK_INTERVAL, 1000). +-define(DEFAULT_MEMORY_CHECK_INTERVAL, 1000). --record(state, {memory_fraction, alarmed}). +-record(state, {memory_fraction, alarmed, timeout, timer}). %%---------------------------------------------------------------------------- @@ -53,9 +53,15 @@ update() -> init(_Args) -> Fraction = os_mon:get_env(memsup, system_memory_high_watermark), - {ok, _Tref} = timer:apply_interval(?MEMORY_CHECK_INTERVAL, - ?MODULE, update, []), - {ok, #state{alarmed = false, memory_fraction = Fraction}}. + TRef = start_timer(?DEFAULT_MEMORY_CHECK_INTERVAL), + {ok, #state{alarmed = false, + memory_fraction = Fraction, + timeout = ?DEFAULT_MEMORY_CHECK_INTERVAL, + timer = TRef}}. + +start_timer(Timeout) -> + {ok, TRef} = timer:apply_interval(Timeout, ?MODULE, update, []), + TRef. %% Export the same API as the real memsup. Note that %% get_sysmem_high_watermark gives an int in the range 0 - 100, while @@ -66,6 +72,15 @@ handle_call(get_sysmem_high_watermark, _From, State) -> handle_call({set_sysmem_high_watermark, Float}, _From, State) -> {reply, ok, State#state{memory_fraction=Float}}; +handle_call(get_check_interval, _From, State) -> + {reply, State#state.timeout, State}; + +handle_call({set_check_interval, Timeout}, _From, State = #state{timer = OldTRef}) -> + {ok, cancel} = timer:cancel(OldTRef), + NewTRef = start_timer(Timeout), + {reply, ok, State#state{timeout = Timeout, + timer = NewTRef}}; + handle_call(_Request, _From, State) -> {noreply, State}. |