You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2014/05/22 20:36:01 UTC

git commit: TS-2831 SPDY statistics.

Repository: trafficserver
Updated Branches:
  refs/heads/master fba9b2e36 -> 7785723e4


TS-2831 SPDY statistics.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7785723e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7785723e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7785723e

Branch: refs/heads/master
Commit: 7785723e475fd498f360cc91b16a617dfb39ae98
Parents: fba9b2e
Author: Alan M. Carroll <am...@network-geographics.com>
Authored: Thu May 22 11:35:41 2014 -0700
Committer: Alan M. Carroll <am...@network-geographics.com>
Committed: Thu May 22 11:35:41 2014 -0700

----------------------------------------------------------------------
 proxy/spdy/SpdyClientSession.cc | 44 ++++++++++++++++++++++++++----------
 proxy/spdy/SpdyClientSession.h  | 11 +--------
 proxy/spdy/SpdyCommon.cc        |  9 +++++---
 proxy/spdy/SpdyCommon.h         | 10 +++++++-
 proxy/spdy/SpdySessionAccept.cc |  1 -
 5 files changed, 48 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7785723e/proxy/spdy/SpdyClientSession.cc
----------------------------------------------------------------------
diff --git a/proxy/spdy/SpdyClientSession.cc b/proxy/spdy/SpdyClientSession.cc
index 602b2ee..2c77ff6 100644
--- a/proxy/spdy/SpdyClientSession.cc
+++ b/proxy/spdy/SpdyClientSession.cc
@@ -32,12 +32,27 @@ static int spdy_process_write(TSEvent event, SpdyClientSession *sm);
 static int spdy_process_fetch(TSEvent event, SpdyClientSession *sm, void *edata);
 static int spdy_process_fetch_header(TSEvent event, SpdyClientSession *sm, TSFetchSM fetch_sm);
 static int spdy_process_fetch_body(TSEvent event, SpdyClientSession *sm, TSFetchSM fetch_sm);
-static uint64_t g_sm_id;
-static uint64_t g_sm_cnt;
+static uint64_t g_sm_id = 1;
+
+void
+SpdyRequest::init(SpdyClientSession *sm, int id)
+{
+  spdy_sm = sm;
+  stream_id = id;
+  headers.clear();
+
+  MD5_Init(&recv_md5);
+  start_time = TShrtime();
+
+  SpdyStatIncrCount(Config::STAT_ACTIVE_STREAM_COUNT, sm);
+  SpdyStatIncrCount(Config::STAT_TOTAL_STREAM_COUNT, sm);
+}
 
 void
 SpdyRequest::clear()
 {
+  SpdyStatDecrCount(Config::STAT_ACTIVE_STREAM_COUNT, spdy_sm);
+
   if (fetch_sm)
     TSFetchDestroy(fetch_sm);
 
@@ -58,14 +73,18 @@ SpdyClientSession::init(NetVConnection * netvc, spdylay_proto_version vers)
 {
   int r;
 
-  atomic_inc(g_sm_cnt);
-
   this->mutex = new_ProxyMutex();
   this->vc = netvc;
   this->req_map.clear();
 
-  r = spdylay_session_server_new(&session, vers,
-                                 &SPDY_CFG.spdy.callbacks, this);
+  r = spdylay_session_server_new(&session, vers, &SPDY_CFG.spdy.callbacks, this);
+
+  // A bit ugly but we need a thread and I don't want to wait until the
+  // session start event in case of a time out generating a decrement
+  // with no increment. It seems a lesser thing to have the thread counts
+  // a little off but globally consistent.
+  SpdyStatIncrCount(Config::STAT_ACTIVE_SESSION_COUNT, netvc);
+
   ink_release_assert(r == 0);
   sm_id = atomic_inc(g_sm_id);
   total_size = 0;
@@ -79,8 +98,10 @@ SpdyClientSession::init(NetVConnection * netvc, spdylay_proto_version vers)
 void
 SpdyClientSession::clear()
 {
-  uint64_t nr_pending;
   int last_event = event;
+
+  SpdyStatDecrCount(Config::STAT_ACTIVE_SESSION_COUNT, this);
+
   //
   // SpdyRequest depends on SpdyClientSession,
   // we should delete it firstly to avoid race.
@@ -131,9 +152,8 @@ SpdyClientSession::clear()
     session = NULL;
   }
 
-  nr_pending = atomic_dec(g_sm_cnt);
-  Debug("spdy-free", "****Delete SpdyClientSession[%" PRIu64 "], last event:%d, nr_pending:%" PRIu64,
-        sm_id, last_event, --nr_pending);
+  Debug("spdy-free", "****Delete SpdyClientSession[%" PRIu64 "], last event:%d" PRIu64,
+        sm_id, last_event);
 }
 
 void
@@ -209,8 +229,8 @@ SpdyClientSession::state_session_readwrite(int event, void * edata)
     ret = spdy_process_fetch((TSEvent)event, this, edata);
   }
 
-  Debug("spdy-event", "++++SpdyClientSession[%" PRIu64 "], EVENT:%d, ret:%d, nr_pending:%" PRIu64,
-        this->sm_id, event, ret, g_sm_cnt);
+  Debug("spdy-event", "++++SpdyClientSession[%" PRIu64 "], EVENT:%d, ret:%d",
+        this->sm_id, event, ret);
 out:
   if (ret) {
     this->clear();

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7785723e/proxy/spdy/SpdyClientSession.h
----------------------------------------------------------------------
diff --git a/proxy/spdy/SpdyClientSession.h b/proxy/spdy/SpdyClientSession.h
index 5845b84..2f37d35 100644
--- a/proxy/spdy/SpdyClientSession.h
+++ b/proxy/spdy/SpdyClientSession.h
@@ -56,16 +56,7 @@ public:
     clear();
   }
 
-  void init(SpdyClientSession *sm, int id)
-  {
-    spdy_sm = sm;
-    stream_id = id;
-    headers.clear();
-
-    MD5_Init(&recv_md5);
-    start_time = TShrtime();
-  }
-
+  void init(SpdyClientSession *sm, int id);
   void clear();
 
   void append_nv(char **nv)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7785723e/proxy/spdy/SpdyCommon.cc
----------------------------------------------------------------------
diff --git a/proxy/spdy/SpdyCommon.cc b/proxy/spdy/SpdyCommon.cc
index 47358c2..0b89bf8 100644
--- a/proxy/spdy/SpdyCommon.cc
+++ b/proxy/spdy/SpdyCommon.cc
@@ -27,8 +27,9 @@
 Config SPDY_CFG;
 
 // statistic names
-// Total # of streams created.
-static char const * const SPDY_STAT_TOTAL_STREAMS_NAME = "proxy.process.spdy.total_streams";
+static char const * const SPDY_STAT_ACTIVE_SESSION_NAME = "proxy.process.spdy.active_sessions";
+static char const * const SPDY_STAT_ACTIVE_STREAM_NAME = "proxy.process.spdy.active_streams";
+static char const * const SPDY_STAT_TOTAL_STREAM_NAME = "proxy.process.spdy.total_streams";
 
 string
 http_date(time_t t)
@@ -52,7 +53,9 @@ spdy_config_load()
 
   // Get our statistics up
   SPDY_CFG.rsb = RecAllocateRawStatBlock(static_cast<int>(Config::N_STATS));
-  RecRegisterRawStat(SPDY_CFG.rsb, RECT_PROCESS, SPDY_STAT_TOTAL_STREAMS_NAME, RECD_INT, RECP_NON_PERSISTENT, static_cast<int>(Config::STAT_TOTAL_STREAMS), RecRawStatSyncCount);
+  RecRegisterRawStat(SPDY_CFG.rsb, RECT_PROCESS, SPDY_STAT_ACTIVE_SESSION_NAME, RECD_INT, RECP_NON_PERSISTENT, static_cast<int>(Config::STAT_ACTIVE_SESSION_COUNT), RecRawStatSyncCount);
+  RecRegisterRawStat(SPDY_CFG.rsb, RECT_PROCESS, SPDY_STAT_ACTIVE_STREAM_NAME, RECD_INT, RECP_NON_PERSISTENT, static_cast<int>(Config::STAT_ACTIVE_STREAM_COUNT), RecRawStatSyncCount);
+  RecRegisterRawStat(SPDY_CFG.rsb, RECT_PROCESS, SPDY_STAT_TOTAL_STREAM_NAME, RECD_INT, RECP_NON_PERSISTENT, static_cast<int>(Config::STAT_TOTAL_STREAM_COUNT), RecRawStatSyncCount);
 
   return 0;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7785723e/proxy/spdy/SpdyCommon.h
----------------------------------------------------------------------
diff --git a/proxy/spdy/SpdyCommon.h b/proxy/spdy/SpdyCommon.h
index 6a701c8..92ab047 100644
--- a/proxy/spdy/SpdyCommon.h
+++ b/proxy/spdy/SpdyCommon.h
@@ -70,7 +70,9 @@ struct Config {
   // Statistics
   /// This is the stat slot index for each statistic.
   enum StatIndex {
-    STAT_TOTAL_STREAMS,
+    STAT_ACTIVE_SESSION_COUNT, ///< Current # of active SPDY sessions.
+    STAT_ACTIVE_STREAM_COUNT, ///< Current # of active SPDY streams.
+    STAT_TOTAL_STREAM_COUNT, ///< Total number of streams created.
     N_STATS ///< Terminal counter, NOT A STAT INDEX.
   };
   RecRawStatBlock* rsb; ///< Container for statistics.
@@ -104,4 +106,10 @@ inline void
 SpdyStatIncrCount(Config::StatIndex idx, Continuation* contp) {
   RecIncrRawStatCount(SPDY_CFG.rsb, contp->mutex->thread_holding, idx, 1);
 }
+
+inline void
+SpdyStatDecrCount(Config::StatIndex idx, Continuation* contp) {
+  RecIncrRawStatCount(SPDY_CFG.rsb, contp->mutex->thread_holding, idx, -1);
+}
+
 #endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7785723e/proxy/spdy/SpdySessionAccept.cc
----------------------------------------------------------------------
diff --git a/proxy/spdy/SpdySessionAccept.cc b/proxy/spdy/SpdySessionAccept.cc
index b8c1d75..e679adc 100644
--- a/proxy/spdy/SpdySessionAccept.cc
+++ b/proxy/spdy/SpdySessionAccept.cc
@@ -52,7 +52,6 @@ SpdySessionAccept::mainEvent(int event, void * edata)
 
 #if TS_HAS_SPDY
     spdy_sm_create(netvc, versmap[this->version], NULL, NULL);
-    SpdyStatIncrCount(Config::STAT_TOTAL_STREAMS, this);
 #else
     Error("accepted a SPDY session, but SPDY support is not available");
     netvc->do_io_close();