summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2010-09-14 15:16:57 +0100
committerSimon MacMullen <simon@rabbitmq.com>2010-09-14 15:16:57 +0100
commit2e077479b0e3e9eea87ba06222c43a8cc171e007 (patch)
tree11f9a13addd4c738e3da6163e56197ad9f573a92
parent404d5dee554290ba474959a74f4a3838b474034c (diff)
downloadrabbitmq-server-2e077479b0e3e9eea87ba06222c43a8cc171e007.tar.gz
Stop stats timer on hibernate.
-rw-r--r--src/rabbit_amqqueue_process.erl8
-rw-r--r--src/rabbit_channel.erl6
-rw-r--r--src/rabbit_event.erl12
3 files changed, 20 insertions, 6 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl
index 4ea7f8a1..8f4c200d 100644
--- a/src/rabbit_amqqueue_process.erl
+++ b/src/rabbit_amqqueue_process.erl
@@ -919,11 +919,13 @@ handle_info(Info, State) ->
handle_pre_hibernate(State = #q{backing_queue_state = undefined}) ->
{hibernate, State};
handle_pre_hibernate(State = #q{backing_queue = BQ,
- backing_queue_state = BQS}) ->
+ backing_queue_state = BQS,
+ stats_timer = StatsTimer}) ->
BQS1 = BQ:handle_pre_hibernate(BQS),
%% no activity for a while == 0 egress and ingress rates
DesiredDuration =
rabbit_memory_monitor:report_ram_duration(self(), infinity),
BQS2 = BQ:set_ram_duration_target(DesiredDuration, BQS1),
- {hibernate, emit_stats(
- stop_rate_timer(State#q{backing_queue_state = BQS2}))}.
+ emit_stats(State),
+ State1 = State#q{stats_timer = rabbit_event:stop_stats_timer(StatsTimer)},
+ {hibernate, stop_rate_timer(State1#q{backing_queue_state = BQS2})}.
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index edc4ca8a..bd52a40c 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -249,9 +249,11 @@ handle_info({'DOWN', _MRef, process, QPid, _Reason}, State) ->
erase_queue_stats(QPid),
{noreply, queue_blocked(QPid, State)}.
-handle_pre_hibernate(State) ->
+handle_pre_hibernate(State = #ch{stats_timer = StatsTimer}) ->
ok = clear_permission_cache(),
- {hibernate, internal_emit_stats(State)}.
+ internal_emit_stats(State),
+ State1 = State#ch{stats_timer = rabbit_event:stop_stats_timer(StatsTimer)},
+ {hibernate, State1}.
terminate(_Reason, State = #ch{state = terminating}) ->
terminate(State);
diff --git a/src/rabbit_event.erl b/src/rabbit_event.erl
index 79d3a553..3ef02517 100644
--- a/src/rabbit_event.erl
+++ b/src/rabbit_event.erl
@@ -34,7 +34,7 @@
-include("rabbit.hrl").
-export([start_link/0]).
--export([init_stats_timer/0, ensure_stats_timer/2]).
+-export([init_stats_timer/0, ensure_stats_timer/2, stop_stats_timer/1]).
-export([reset_stats_timer/1]).
-export([stats_level/1, if_enabled/2]).
-export([notify/2]).
@@ -72,6 +72,7 @@
-spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()).
-spec(init_stats_timer/0 :: () -> state()).
-spec(ensure_stats_timer/2 :: (state(), timer_fun()) -> state()).
+-spec(stop_stats_timer/1 :: (state()) -> state()).
-spec(reset_stats_timer/1 :: (state()) -> state()).
-spec(stats_level/1 :: (state()) -> level()).
-spec(if_enabled/2 :: (state(), timer_fun()) -> 'ok').
@@ -101,6 +102,7 @@ start_link() ->
%%
%% Pre-hibernation:
%% internal_emit_stats
+%% stop_stats_timer(Timer)
%%
%% internal_emit_stats:
%% notify(stats)
@@ -118,6 +120,14 @@ ensure_stats_timer(State = #state{timer = undefined}, Fun) ->
ensure_stats_timer(State, _Fun) ->
State.
+stop_stats_timer(State = #state{level = none}) ->
+ State;
+stop_stats_timer(State = #state{timer = undefined}) ->
+ State;
+stop_stats_timer(State = #state{timer = TRef}) ->
+ {ok, cancel} = timer:cancel(TRef),
+ State#state{timer = undefined}.
+
reset_stats_timer(State) ->
State#state{timer = undefined}.