]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: track average uptime of sessions
authorVenky Shankar <vshankar@redhat.com>
Tue, 24 Jul 2018 03:47:02 +0000 (23:47 -0400)
committerVenky Shankar <vshankar@redhat.com>
Thu, 4 Oct 2018 09:13:19 +0000 (14:43 +0530)
Average session age math improvements by Patrick.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
Signed-off-by: Venky Shankar <vshankar@redhat.com>
(cherry picked from commit d2627b98d0c1477d664d00384ef033d323b26957)

Conflicts:
        src/mds/SessionMap.h

src/mds/MDSRank.cc
src/mds/SessionMap.cc
src/mds/SessionMap.h

index ede68a447cba1dd4b626d3d47d4e665b81bc0230..3c6073e9689a7627e2652d791093abdd48856e78 100644 (file)
@@ -258,6 +258,9 @@ void MDSRankDispatcher::tick()
   // make sure mds log flushes, trims periodically
   mdlog->flush();
 
+  // update average session uptime
+  sessionmap.update_average_session_age();
+
   if (is_active() || is_stopping()) {
     mdcache->trim();
     mdcache->trim_client_leases();
index 6dbb809c1bf6303defddcb61b81b016a33507a0e..15776ea7144c68bff8399d792782733f7fdb06aa 100644 (file)
@@ -62,6 +62,9 @@ void SessionMap::register_perfcounters()
               "Sessions currently stale");
   plb.add_u64(l_mdssm_total_load, "total_load", "Total Load");
   plb.add_u64(l_mdssm_avg_load, "average_load", "Average Load");
+  plb.add_u64(l_mdssm_avg_session_uptime, "avg_session_uptime",
+               "Average session uptime");
+
   logger = plb.create_perf_counters();
   g_ceph_context->get_perfcounters_collection()->add(logger);
 }
@@ -627,6 +630,8 @@ void SessionMap::add_session(Session *s)
   by_state_entry->second->push_back(&s->item_session_list);
   s->get();
 
+  update_average_birth_time(*s);
+
   logger->set(l_mdssm_session_count, session_map.size());
   logger->inc(l_mdssm_session_add);
 }
@@ -635,6 +640,8 @@ void SessionMap::remove_session(Session *s)
 {
   dout(10) << __func__ << " s=" << s << " name=" << s->info.inst.name << dendl;
 
+  update_average_birth_time(*s, false);
+
   s->trim_completed_requests(0);
   s->item_session_list.remove_myself();
   session_map.erase(s->info.inst.name);
@@ -1005,6 +1012,15 @@ void SessionMap::handle_conf_change(const struct md_config_t *conf,
   }
 }
 
+void SessionMap::update_average_session_age() {
+  if (!session_map.size()) {
+    return;
+  }
+
+  double avg_uptime = std::chrono::duration<double>(clock::now()-avg_birth_time).count();
+  logger->set(l_mdssm_avg_session_uptime, (uint64_t)avg_uptime);
+}
+
 int SessionFilter::parse(
     const std::vector<std::string> &args,
     std::stringstream *ss)
index 806cf0fcb7d727aae0154b9d3b531978a1218d09..c22e072ca5d8ff20f84b456a0ce74fcfd65202b9 100644 (file)
@@ -45,6 +45,7 @@ enum {
   l_mdssm_session_stale,
   l_mdssm_total_load,
   l_mdssm_avg_load,
+  l_mdssm_avg_session_uptime,
   l_mdssm_last,
 };
 
@@ -112,6 +113,12 @@ private:
   mutable DecayCounter load_avg;
   DecayRate    load_avg_rate;
 
+  // session start time -- used to track average session time
+  // note that this is initialized in the constructor rather
+  // than at the time of adding a session to the sessionmap
+  // as journal replay of sessionmap will not call add_session().
+  time birth_time;
+
 public:
 
   void push_pv(version_t pv)
@@ -221,6 +228,10 @@ public:
     load_avg.hit(ceph_clock_now(), load_avg_rate);
   }
 
+  time get_birth_time() const {
+    return birth_time;
+  }
+
   // -- caps --
 private:
   version_t cap_push_seq;        // cap push seq #
@@ -343,8 +354,8 @@ public:
 
   Session() : 
     state(STATE_CLOSED), state_seq(0), importing_count(0),
-    recall_count(0), recall_release_count(0),
-    auth_caps(g_ceph_context),
+    birth_time(clock::now()), recall_count(0),
+    recall_release_count(0), auth_caps(g_ceph_context),
     connection(NULL), item_session_list(this),
     requests(0),  // member_offset passed to front() manually
     cap_push_seq(0),
@@ -484,6 +495,7 @@ public:
   map<int,xlist<Session*>* > by_state;
   uint64_t set_state(Session *session, int state);
   map<version_t, list<MDSInternalContextBase*> > commit_waiters;
+  void update_average_session_age();
 
   explicit SessionMap(MDSRank *m) : mds(m),
                       projected(0), committing(0), committed(0),
@@ -699,10 +711,32 @@ public:
                      MDSGatherBuilder *gather_bld);
 
 private:
+  time avg_birth_time = time::min();
+
   uint64_t get_session_count_in_state(int state) {
     return !is_any_state(state) ? 0 : by_state[state]->size();
   }
 
+  void update_average_birth_time(const Session &s, bool added=true) {
+    uint32_t sessions = session_map.size();
+    time birth_time = s.get_birth_time();
+
+    if (sessions == 1) {
+      avg_birth_time = added ? birth_time : time::min();
+      return;
+    }
+
+    if (added) {
+      avg_birth_time = clock::time_point(
+        ((avg_birth_time - time::min()) / sessions) * (sessions - 1) +
+        (birth_time - time::min()) / sessions);
+    } else {
+      avg_birth_time = clock::time_point(
+        ((avg_birth_time - time::min()) / (sessions - 1)) * sessions -
+        (birth_time - time::min()) / (sessions - 1));
+    }
+  }
+
 public:
   void hit_session(Session *session);
   void handle_conf_change(const struct md_config_t *conf,