summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-01-14 12:03:38 +0000
committerMatthias Radestock <matthias@lshift.net>2009-01-14 12:03:38 +0000
commita8505e2361de1d8d758d7bc2b7aa1b7c5690a573 (patch)
tree30d7e3001dbdcc8c8651fe0375c85c337d0150fe
parentcc6c502811e9656137431fa3a81ed87de66591db (diff)
downloadrabbitmq-server-a8505e2361de1d8d758d7bc2b7aa1b7c5690a573.tar.gz
make the channel process hibernate after 1s of idleness
to conserve resources
-rw-r--r--src/rabbit_channel.erl23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index 6abca523..9659d080 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -46,6 +46,8 @@
username, virtual_host,
most_recently_declared_queue, consumer_mapping}).
+-define(HIBERNATE_AFTER, 1000).
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
@@ -105,15 +107,15 @@ init([ReaderPid, WriterPid, Username, VHost]) ->
consumer_mapping = dict:new()}}.
handle_call(_Request, _From, State) ->
- {noreply, State}.
+ noreply(State).
handle_cast({method, Method, Content}, State) ->
try handle_method(Method, Content, State) of
{reply, Reply, NewState} ->
ok = rabbit_writer:send_command(NewState#ch.writer_pid, Reply),
- {noreply, NewState};
+ noreply(NewState);
{noreply, NewState} ->
- {noreply, NewState};
+ noreply(NewState);
stop ->
{stop, normal, State#ch{state = terminating}}
catch
@@ -131,22 +133,27 @@ handle_cast(terminate, State) ->
handle_cast({command, Msg}, State = #ch{writer_pid = WriterPid}) ->
ok = rabbit_writer:send_command(WriterPid, Msg),
- {noreply, State};
+ noreply(State);
handle_cast({deliver, ConsumerTag, AckRequired, Msg},
State = #ch{writer_pid = WriterPid,
next_tag = DeliveryTag}) ->
State1 = lock_message(AckRequired, {DeliveryTag, ConsumerTag, Msg}, State),
ok = internal_deliver(WriterPid, true, ConsumerTag, DeliveryTag, Msg),
- {noreply, State1#ch{next_tag = DeliveryTag + 1}};
+ noreply(State1#ch{next_tag = DeliveryTag + 1});
handle_cast({conserve_memory, Conserve}, State) ->
ok = rabbit_writer:send_command(
State#ch.writer_pid, #'channel.flow'{active = not(Conserve)}),
- {noreply, State}.
+ noreply(State).
handle_info({'EXIT', _Pid, Reason}, State) ->
- {noreply, Reason, State}.
+ {noreply, Reason, State};
+
+handle_info(timeout, State) ->
+ %% TODO: Once we drop support for R11B-5, we can change this to
+ %% {noreply, State, hibernate};
+ proc_lib:hibernate(gen_server2, enter_loop, [?MODULE, [], State]).
terminate(_Reason, #ch{writer_pid = WriterPid, state = terminating}) ->
rabbit_writer:shutdown(WriterPid);
@@ -164,6 +171,8 @@ code_change(_OldVsn, State, _Extra) ->
%%---------------------------------------------------------------------------
+noreply(NewState) -> {noreply, NewState, ?HIBERNATE_AFTER}.
+
return_ok(State, true, _Msg) -> {noreply, State};
return_ok(State, false, Msg) -> {reply, Msg, State}.