diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-20 00:17:44 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-20 00:17:44 +0100 |
commit | 55bc75b7a559a28f9e6ca5fdd5737cc609fcc86b (patch) | |
tree | 7e3701c1974ccd4bbdf283318016ff671c11a451 | |
parent | 8dd2e7c274ef231f9625cb7066fb8fb546f7552a (diff) | |
download | rabbitmq-server-55bc75b7a559a28f9e6ca5fdd5737cc609fcc86b.tar.gz |
replace timer:apply_interval with timer:send_intervalbug24508
The latter doesn't churn processes and doesn't require exporting of
functions we otherwise wouldn't.
-rw-r--r-- | src/rabbit_memory_monitor.erl | 15 | ||||
-rw-r--r-- | src/vm_memory_monitor.erl | 14 |
2 files changed, 10 insertions, 19 deletions
diff --git a/src/rabbit_memory_monitor.erl b/src/rabbit_memory_monitor.erl index 3bd8eeef..3deb9580 100644 --- a/src/rabbit_memory_monitor.erl +++ b/src/rabbit_memory_monitor.erl @@ -24,7 +24,7 @@ -behaviour(gen_server2). --export([start_link/0, update/0, register/2, deregister/1, +-export([start_link/0, register/2, deregister/1, report_ram_duration/2, stop/0]). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -69,7 +69,6 @@ -ifdef(use_specs). -spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()). --spec(update/0 :: () -> 'ok'). -spec(register/2 :: (pid(), {atom(),atom(),[any()]}) -> 'ok'). -spec(deregister/1 :: (pid()) -> 'ok'). -spec(report_ram_duration/2 :: @@ -85,9 +84,6 @@ start_link() -> gen_server2:start_link({local, ?SERVER}, ?MODULE, [], []). -update() -> - gen_server2:cast(?SERVER, update). - register(Pid, MFA = {_M, _F, _A}) -> gen_server2:call(?SERVER, {register, Pid, MFA}, infinity). @@ -106,8 +102,7 @@ stop() -> %%---------------------------------------------------------------------------- init([]) -> - {ok, TRef} = timer:apply_interval(?DEFAULT_UPDATE_INTERVAL, - ?SERVER, update, []), + {ok, TRef} = timer:send_interval(?DEFAULT_UPDATE_INTERVAL, update), Ets = ets:new(?TABLE_NAME, [set, private, {keypos, #process.pid}]), @@ -153,9 +148,6 @@ handle_call({register, Pid, MFA}, _From, handle_call(_Request, _From, State) -> {noreply, State}. -handle_cast(update, State) -> - {noreply, internal_update(State)}; - handle_cast({deregister, Pid}, State) -> {noreply, internal_deregister(Pid, true, State)}; @@ -165,6 +157,9 @@ handle_cast(stop, State) -> handle_cast(_Request, State) -> {noreply, State}. +handle_info(update, State) -> + {noreply, internal_update(State)}; + handle_info({'DOWN', _MRef, process, Pid, _Reason}, State) -> {noreply, internal_deregister(Pid, false, State)}; diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl index 35ee1e51..8973a4f7 100644 --- a/src/vm_memory_monitor.erl +++ b/src/vm_memory_monitor.erl @@ -32,7 +32,7 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). --export([update/0, get_total_memory/0, get_vm_limit/0, +-export([get_total_memory/0, get_vm_limit/0, get_check_interval/0, set_check_interval/1, get_vm_memory_high_watermark/0, set_vm_memory_high_watermark/1, get_memory_limit/0]). @@ -59,7 +59,6 @@ -ifdef(use_specs). -spec(start_link/1 :: (float()) -> rabbit_types:ok_pid_or_error()). --spec(update/0 :: () -> 'ok'). -spec(get_total_memory/0 :: () -> (non_neg_integer() | 'unknown')). -spec(get_vm_limit/0 :: () -> non_neg_integer()). -spec(get_check_interval/0 :: () -> non_neg_integer()). @@ -74,9 +73,6 @@ %% Public API %%---------------------------------------------------------------------------- -update() -> - gen_server:cast(?SERVER, update). - get_total_memory() -> get_total_memory(os:type()). @@ -135,12 +131,12 @@ handle_call(get_memory_limit, _From, State) -> handle_call(_Request, _From, State) -> {noreply, State}. -handle_cast(update, State) -> - {noreply, internal_update(State)}; - handle_cast(_Request, State) -> {noreply, State}. +handle_info(update, State) -> + {noreply, internal_update(State)}; + handle_info(_Info, State) -> {noreply, State}. @@ -200,7 +196,7 @@ emit_update_info(State, MemUsed, MemLimit) -> [State, MemUsed, MemLimit]). start_timer(Timeout) -> - {ok, TRef} = timer:apply_interval(Timeout, ?MODULE, update, []), + {ok, TRef} = timer:send_interval(Timeout, update), TRef. %% According to http://msdn.microsoft.com/en-us/library/aa366778(VS.85).aspx |