summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-10-03 09:21:23 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-10-03 09:21:23 +0100
commit76b495bc5546268c0f7a847574459552c1f6163a (patch)
treeadcfe3e2f662bb6470d242e8688fc87339217ba2 /src
parentca592e6a4edbbb028b387943aadc44c22fadb0b8 (diff)
downloadrabbitmq-server-git-76b495bc5546268c0f7a847574459552c1f6163a.tar.gz
improve performance by bypassing mnesia for queue lookup
This is worth ~2% on "MCM -a" when running with two Erlang schedulers, and drops rabbit_router:lookup_qpids/1 from #21 to #42 in the fprof analysis of the channel process.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_router.erl21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl
index d453a8707e..36fdb203ce 100644
--- a/src/rabbit_router.erl
+++ b/src/rabbit_router.erl
@@ -107,9 +107,16 @@ check_delivery(true, _ , {false, []}) -> {unroutable, []};
check_delivery(_ , true, {_ , []}) -> {not_delivered, []};
check_delivery(_ , _ , {_ , Qs}) -> {routed, Qs}.
+%% Normally we'd call mnesia:dirty_read/1 here, but that is quite
+%% expensive due to general mnesia overheads (figuring out table types
+%% and locations, etc). We get away with bypassing these because we
+%% know that the table
+%% - is not the schema table
+%% - has a local ram copy
+%% - does not have any indices
lookup_qpids(QNames) ->
lists:foldl(fun (QName, QPids) ->
- case mnesia:dirty_read({rabbit_queue, QName}) of
+ case ets:lookup(rabbit_queue, QName) of
[#amqqueue{pid = QPid, slave_pids = SPids}] ->
[QPid | SPids ++ QPids];
[] ->
@@ -118,16 +125,8 @@ lookup_qpids(QNames) ->
end, [], QNames).
%% Normally we'd call mnesia:dirty_select/2 here, but that is quite
-%% expensive due to
-%%
-%% 1) general mnesia overheads (figuring out table types and
-%% locations, etc). We get away with bypassing these because we know
-%% that the table
-%% - is not the schema table
-%% - has a local ram copy
-%% - does not have any indices
-%%
-%% 2) 'fixing' of the table with ets:safe_fixtable/2, which is wholly
+%% expensive for the same reasons as above, and, additionally, due to
+%% mnesia 'fixing' the table with ets:safe_fixtable/2, which is wholly
%% unnecessary. According to the ets docs (and the code in erl_db.c),
%% 'select' is safe anyway ("Functions that internally traverse over a
%% table, like select and match, will give the same guarantee as