summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-10-03 10:18:48 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-10-03 10:18:48 +0100
commit88a9a3402a628c7e8061105746b1a380503095d8 (patch)
treecec6cd80c6b640c34f992f5ecbf95ace10fe9b17 /src
parent76b495bc5546268c0f7a847574459552c1f6163a (diff)
downloadrabbitmq-server-git-88a9a3402a628c7e8061105746b1a380503095d8.tar.gz
optimise resource lookup
This is worth ~2% in "MCM -a" when running with two Erlang schedulers, and drops rabbit_misc:dirty_read/1 from #21 to #49 in the fprof analysis of the publisher channel.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_misc.erl11
-rw-r--r--src/rabbit_router.erl7
2 files changed, 10 insertions, 8 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index b1cf45e7fc..13a553f124 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -257,8 +257,15 @@ val({Type, Value}) ->
end,
lists:flatten(io_lib:format(Fmt, [Value, Type])).
-dirty_read(ReadSpec) ->
- case mnesia:dirty_read(ReadSpec) of
+%% 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 tables we are looking at here
+%% - are not the schema table
+%% - have a local ram copy
+%% - do not have any indices
+dirty_read({Table, Key}) ->
+ case ets:lookup(Table, Key) of
[Result] -> {ok, Result};
[] -> {error, not_found}
end.
diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl
index 36fdb203ce..e9c4479a63 100644
--- a/src/rabbit_router.erl
+++ b/src/rabbit_router.erl
@@ -108,12 +108,7 @@ 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
+%% expensive for the reasons explained in rabbit_misc:dirty_read/1.
lookup_qpids(QNames) ->
lists:foldl(fun (QName, QPids) ->
case ets:lookup(rabbit_queue, QName) of