diff options
author | Carl C. Trieloff <cctrieloff@apache.org> | 2011-03-11 00:37:04 +0000 |
---|---|---|
committer | Carl C. Trieloff <cctrieloff@apache.org> | 2011-03-11 00:37:04 +0000 |
commit | e6557a19fd89a8cb434886127917dc3b6947cf41 (patch) | |
tree | 5e49f7b755fa9f946cf8141e688f9efdce6fe9bc /cpp/src/qpid/broker/TopicExchange.cpp | |
parent | 8dfea3464706ac819d7500e19a4dd77bccf761b0 (diff) | |
download | qpid-python-e6557a19fd89a8cb434886127917dc3b6947cf41.tar.gz |
QPID-3138 Topic exchange perf improvement
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1080411 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/TopicExchange.cpp')
-rw-r--r-- | cpp/src/qpid/broker/TopicExchange.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/cpp/src/qpid/broker/TopicExchange.cpp b/cpp/src/qpid/broker/TopicExchange.cpp index 1b0fe71bcf..f3baf00d1f 100644 --- a/cpp/src/qpid/broker/TopicExchange.cpp +++ b/cpp/src/qpid/broker/TopicExchange.cpp @@ -221,6 +221,7 @@ TopicExchange::TopicExchange(const std::string& _name, bool _durable, bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* args) { + ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit. string fedOp(args ? args->getAsString(qpidFedOp) : fedOpBind); string fedTags(args ? args->getAsString(qpidFedTags) : ""); string fedOrigin(args ? args->getAsString(qpidFedOrigin) : ""); @@ -288,6 +289,7 @@ bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, cons } bool TopicExchange::unbind(Queue::shared_ptr queue, const string& constRoutingKey, const FieldTable* /*args*/){ + ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function exit. RWlock::ScopedWlock l(lock); string routingKey = normalize(constRoutingKey); BindingKey* bk = bindingTree.getBindingKey(routingKey); @@ -333,13 +335,24 @@ bool TopicExchange::isBound(Queue::shared_ptr queue, const string& pattern) void TopicExchange::route(Deliverable& msg, const string& routingKey, const FieldTable* /*args*/) { // Note: PERFORMANCE CRITICAL!!! - BindingList b(new std::vector<boost::shared_ptr<qpid::broker::Exchange::Binding> >); + BindingList b; + std::map<std::string, BindingList>::iterator it; + { // only lock the cache for read + RWlock::ScopedRlock cl(cacheLock); + it = bindingCache.find(routingKey); + } PreRoute pr(msg, this); - BindingsFinderIter bindingsFinder(b); + if (it == bindingCache.end()) // no cache hit { RWlock::ScopedRlock l(lock); + b = BindingList(new std::vector<boost::shared_ptr<qpid::broker::Exchange::Binding> >); + BindingsFinderIter bindingsFinder(b); bindingTree.iterateMatch(routingKey, bindingsFinder); - } + RWlock::ScopedWlock cwl(cacheLock); + bindingCache[routingKey] = b; // update cache + }else { + b = it->second; + } doRoute(msg, b); } |