summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-01-19 14:38:43 +0000
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-01-19 14:38:43 +0000
commit69f35fc60d84b1ffe4424dfe7d47f909bec8e423 (patch)
tree3b8d89859cfb6955178fdd37210aa10212e203fe
parentab3613f8133c81c97b6eb19e03d2c9736d36772d (diff)
downloadrabbitmq-server-bug23637.tar.gz
replace the sort with a gb_treebug23637
Instead of creating a list and sorting it, insert the MsgSeqNos into a gb_tree. Dicts and orddicts are slower.
-rw-r--r--src/rabbit_amqqueue_process.erl27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl
index 38b83117..b0aea012 100644
--- a/src/rabbit_amqqueue_process.erl
+++ b/src/rabbit_amqqueue_process.erl
@@ -431,27 +431,22 @@ confirm_messages(Guids, State = #q{guid_to_channel = GTC}) ->
fun(Guid, {CMs, GTC0}) ->
case dict:find(Guid, GTC0) of
{ok, {ChPid, MsgSeqNo}} ->
- {[{ChPid, MsgSeqNo} | CMs], dict:erase(Guid, GTC0)};
+ {gb_trees_cons(ChPid, MsgSeqNo, CMs),
+ dict:erase(Guid, GTC0)};
_ ->
{CMs, GTC0}
end
- end, {[], GTC}, Guids),
- case lists:usort(CMs) of
- [{Ch, MsgSeqNo} | CMs1] ->
- [rabbit_channel:confirm(ChPid, MsgSeqNos) ||
- {ChPid, MsgSeqNos} <- group_confirms_by_channel(
- CMs1, [{Ch, [MsgSeqNo]}])];
- [] ->
- ok
- end,
+ end, {gb_trees:empty(), GTC}, Guids),
+ gb_trees:map(fun(ChPid, MsgSeqNos) ->
+ rabbit_channel:confirm(ChPid, MsgSeqNos)
+ end, CMs),
State#q{guid_to_channel = GTC1}.
-group_confirms_by_channel([], Acc) ->
- Acc;
-group_confirms_by_channel([{Ch, Msg1} | CMs], [{Ch, Msgs} | Acc]) ->
- group_confirms_by_channel(CMs, [{Ch, [Msg1 | Msgs]} | Acc]);
-group_confirms_by_channel([{Ch, Msg1} | CMs], Acc) ->
- group_confirms_by_channel(CMs, [{Ch, [Msg1]} | Acc]).
+gb_trees_cons(Key, Value, Tree) ->
+ case gb_trees:lookup(Key, Tree) of
+ {value, Values} -> gb_trees:update(Key, [Value | Values], Tree);
+ none -> gb_trees:insert(Key, [Value], Tree)
+ end.
record_confirm_message(#delivery{msg_seq_no = undefined}, State) ->
{no_confirm, State};