]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: in before delete of intrusive based perfcounters cache
authorAli Maredia <amaredia@redhat.com>
Fri, 21 Oct 2022 06:00:51 +0000 (02:00 -0400)
committerAli Maredia <amaredia@redhat.com>
Fri, 28 Oct 2022 12:24:43 +0000 (08:24 -0400)
Signed-off-by: Ali Maredia <amaredia@redhat.com>
src/common/labeled_perf_counters.h
src/common/perf_counters_cache.h
src/rgw/rgw_perf_counters.cc
src/rgw/rgw_perf_counters.h

index d35bfbe98d9f81e9519809b116b7025e4d4f61b6..edc70f086360c10ad3ef08860e2a8a77bdd506e9 100644 (file)
@@ -186,6 +186,7 @@ public:
       if (histogram) {
         histogram->reset();
       }
+      accessed = false;
     }
 
     // read <sum, count> safely by making sure the post- and pre-count
index 11d15e5b1bb8fdf9395e98f87c7e9d03b59152e3..27fe1dac2d8fa1a52ba37ac7f48d608ae2aed44a 100644 (file)
@@ -58,6 +58,7 @@ public:
         ceph::common::LabeledPerfCounters *labeled_counters = lplb->create_perf_counters();
         cct->get_labeledperfcounters_collection()->add(labeled_counters);
         ref->labeled_perfcounters_instance = labeled_counters;
+        curr_size++;
       }
     }
   }
@@ -117,4 +118,86 @@ public:
   }
 };
 
+class PerfCountersCache2 {
+
+private:
+  CephContext *cct;
+  size_t curr_size = 0; 
+  size_t target_size = 0; 
+  ceph::common::LabeledPerfCountersBuilder *default_lplb;
+  std::unordered_map<std::string, ceph::common::LabeledPerfCounters*> cache;
+
+public:
+
+  ceph::common::LabeledPerfCounters* get(std::string key) {
+    auto got = cache.find(key);
+    if(got != cache.end()) {
+      return got->second;
+    }
+    return NULL;
+  }
+
+  //std::pair<bool, LabeledPerfCounter*> add(std::string key, ceph::common::LabeledPerfCountersBuilder *lplb = NULL)
+  void add(std::string key) {
+    auto labeled_counters = get(key);
+    if (!labeled_counters) {
+      if(curr_size < target_size) {
+        // perf counters instance creation code
+        labeled_counters = default_lplb->create_perf_counters();
+        cct->get_labeledperfcounters_collection()->add(labeled_counters);
+        cache[key] = labeled_counters;
+        curr_size++;
+      }
+    }
+  }
+
+  void inc(std::string label, int indx, uint64_t v) {
+    auto labeled_counters = get(label);
+    if(labeled_counters) {
+      labeled_counters->inc(indx, v);
+    }
+  }
+
+  void dec(std::string label, int indx, uint64_t v) {
+    auto labeled_counters = get(label);
+    if(labeled_counters) {
+      labeled_counters->inc(indx, v);
+    }
+  }
+
+  void set_counter(std::string label, int indx, uint64_t val) {
+    auto labeled_counters = get(label);
+    if(labeled_counters) {
+      labeled_counters->set(indx, val);
+    }
+  }
+
+  uint64_t get_counter(std::string label, int indx) {
+    auto labeled_counters = get(label);
+    uint64_t val = 0;
+    if(labeled_counters) {
+      val = labeled_counters->get(indx);
+    }
+    return val;
+  }
+
+  // for use right before destructor would get called
+  void clear_cache() {
+    for(auto it = cache.begin(); it != cache.end(); ++it ) {
+      ceph_assert(it->second);
+      cct->get_labeledperfcounters_collection()->remove(it->second);
+      delete it->second;
+      curr_size--;
+    }
+  }
+
+  PerfCountersCache2(CephContext *_cct, size_t _target_size, ceph::common::LabeledPerfCountersBuilder *_lplb) : cct(_cct), target_size(_target_size), default_lplb(_lplb) {}
+
+  ~PerfCountersCache2() {
+    delete default_lplb;
+    default_lplb = NULL;
+  }
+
+};
+
 #endif
index 7800218c3d32d2770da8c7571b1ff35a06ae816c..8e94619673ed7397f4d83875b5a10ba9add9b453 100644 (file)
@@ -6,7 +6,7 @@
 #include "common/ceph_context.h"
 
 PerfCounters *perfcounter = NULL;
-PerfCountersCache *perf_counters_cache = NULL;
+PerfCountersCache2 *perf_counters_cache = NULL;
 
 int rgw_perf_start(CephContext *cct)
 {
@@ -116,7 +116,7 @@ int rgw_perf_start(CephContext *cct)
   lplb->add_u64_counter(l_rgw_lua_script_fail, "lua_script_fail", "Failed executions of lua scripts");
 
   uint64_t target_size = cct->_conf.get_val<uint64_t>("rgw_labeled_perfcounters_size");
-  perf_counters_cache = new PerfCountersCache(cct, target_size, lplb);
+  perf_counters_cache = new PerfCountersCache2(cct, target_size, lplb);
   lplb = NULL;
   return 0;
 }
@@ -126,6 +126,7 @@ void rgw_perf_stop(CephContext *cct)
   ceph_assert(perfcounter);
   cct->get_perfcounters_collection()->remove(perfcounter);
   delete perfcounter;
+  perf_counters_cache->clear_cache();
   delete perf_counters_cache;
 }
 
index 0c3a94061ed9d275bf2430c1173fb97f1c202066..8efdaebf7cefa92e9825866b87a6f4f067a4b20f 100644 (file)
@@ -7,7 +7,7 @@
 #include "common/labeled_perf_counters.h"
 
 extern PerfCounters *perfcounter;
-extern PerfCountersCache *perf_counters_cache;
+extern PerfCountersCache2 *perf_counters_cache;
 
 extern int rgw_perf_start(CephContext *cct);
 extern void rgw_perf_stop(CephContext *cct);