]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os: WBThrottle: optimize map to unordered_map 3148/head
authorNing Yao <zay11022@gmail.com>
Tue, 23 Dec 2014 05:52:39 +0000 (05:52 +0000)
committerNing Yao <zay11022@gmail.com>
Tue, 23 Dec 2014 05:52:39 +0000 (05:52 +0000)
Using unordered_map to save the cpu cost and acceralate map::find() operation.

Signed-off-by: Ning Yao <zay11022@gmail.com>
src/os/WBThrottle.cc
src/os/WBThrottle.h

index 7d0bcf6f45f2169cc34855e98522940fc4e6983b..828c841619629757d05a717d6938718f7e046b20 100644 (file)
@@ -145,7 +145,7 @@ bool WBThrottle::get_next_should_flush(
   assert(!pending_wbs.empty());
   ghobject_t obj(pop_object());
   
-  map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
+  ceph::unordered_map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
     pending_wbs.find(obj);
   *next = boost::make_tuple(obj, i->second.second, i->second.first);
   pending_wbs.erase(i);
@@ -189,7 +189,7 @@ void WBThrottle::queue_wb(
   bool nocache)
 {
   Mutex::Locker l(lock);
-  map<ghobject_t, pair<PendingWB, FDRef> >::iterator wbiter =
+  ceph::unordered_map<ghobject_t, pair<PendingWB, FDRef> >::iterator wbiter =
     pending_wbs.find(hoid);
   if (wbiter == pending_wbs.end()) {
     wbiter = pending_wbs.insert(
@@ -215,7 +215,7 @@ void WBThrottle::queue_wb(
 void WBThrottle::clear()
 {
   Mutex::Locker l(lock);
-  for (map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
+  for (ceph::unordered_map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
         pending_wbs.begin();
        i != pending_wbs.end();
        ++i) {
@@ -236,7 +236,7 @@ void WBThrottle::clear_object(const ghobject_t &hoid)
   Mutex::Locker l(lock);
   while (clearing == hoid)
     cond.Wait(lock);
-  map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
+  ceph::unordered_map<ghobject_t, pair<PendingWB, FDRef> >::iterator i =
     pending_wbs.find(hoid);
   if (i == pending_wbs.end())
     return;
index f643e39fad88c2bbfb03c6c255da0ccaa5cbaf59..b3fd9e01d23cb412c9fabf5de01bc4726119cfba 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef WBTHROTTLE_H
 #define WBTHROTTLE_H
 
-#include <map>
+#include "include/unordered_map.h"
 #include <boost/tuple/tuple.hpp>
 #include "include/memory.h"
 #include "include/buffer.h"
@@ -45,7 +45,6 @@ enum {
  */
 class WBThrottle : Thread, public md_config_obs_t {
   ghobject_t clearing;
-
   /* *_limits.first is the start_flusher limit and
    * *_limits.second is the hard limit
    */
@@ -90,10 +89,10 @@ class WBThrottle : Thread, public md_config_obs_t {
    * Flush objects in lru order
    */
   list<ghobject_t> lru;
-  map<ghobject_t, list<ghobject_t>::iterator> rev_lru;
+  ceph::unordered_map<ghobject_t, list<ghobject_t>::iterator> rev_lru;
   void remove_object(const ghobject_t &oid) {
     assert(lock.is_locked());
-    map<ghobject_t, list<ghobject_t>::iterator>::iterator iter =
+    ceph::unordered_map<ghobject_t, list<ghobject_t>::iterator>::iterator iter =
       rev_lru.find(oid);
     if (iter == rev_lru.end())
       return;
@@ -114,7 +113,7 @@ class WBThrottle : Thread, public md_config_obs_t {
     rev_lru.insert(make_pair(oid, --lru.end()));
   }
 
-  map<ghobject_t, pair<PendingWB, FDRef> > pending_wbs;
+  ceph::unordered_map<ghobject_t, pair<PendingWB, FDRef> > pending_wbs;
 
   /// get next flush to perform
   bool get_next_should_flush(