You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by vm...@apache.org on 2010/05/15 05:31:39 UTC

svn commit: r944551 - in /trafficserver/traffic/trunk: iocore/eventsystem/ proxy/ proxy/api/ts/ proxy/http2/ proxy/mgmt2/

Author: vmamidi
Date: Sat May 15 03:31:38 2010
New Revision: 944551

URL: http://svn.apache.org/viewvc?rev=944551&view=rev
Log:
TS-157 ---- Raghav's stats changes

Modified:
    trafficserver/traffic/trunk/iocore/eventsystem/I_EThread.h
    trafficserver/traffic/trunk/iocore/eventsystem/UnixEThread.cc
    trafficserver/traffic/trunk/proxy/InkAPI.cc
    trafficserver/traffic/trunk/proxy/Main.cc
    trafficserver/traffic/trunk/proxy/Makefile.am
    trafficserver/traffic/trunk/proxy/api/ts/InkAPIPrivateIOCore.h
    trafficserver/traffic/trunk/proxy/api/ts/ts.h
    trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
    trafficserver/traffic/trunk/proxy/http2/HttpSM.h
    trafficserver/traffic/trunk/proxy/mgmt2/RecordsConfig.cc

Modified: trafficserver/traffic/trunk/iocore/eventsystem/I_EThread.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/I_EThread.h?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/I_EThread.h (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/I_EThread.h Sat May 15 03:31:38 2010
@@ -30,6 +30,7 @@
 #include "I_PriorityEventQueue.h"
 #include "I_ProxyAllocator.h"
 #include "I_ProtectedQueue.h"
+#include <vector>
 
 #define PER_THREAD_DATA (1024*1024)
 
@@ -346,6 +347,9 @@ public:
   ThreadType tt;
   Event *oneevent;              // For dedicated event thread
   ink_sem *eventsem;            // For dedicated event thread
+
+  std::vector<long long> thread_stats;
+  ProxyMutex *thread_stats_mutex;
 };
 
 /**

Modified: trafficserver/traffic/trunk/iocore/eventsystem/UnixEThread.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/UnixEThread.cc?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/UnixEThread.cc (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/UnixEThread.cc Sat May 15 03:31:38 2010
@@ -48,6 +48,7 @@ EThread::EThread()
    tt(REGULAR), eventsem(NULL)
 {
   memset(thread_private, 0, PER_THREAD_DATA);
+  thread_stats_mutex = new_ProxyMutex();
 }
 
 EThread::EThread(ThreadType att, int anid)
@@ -64,6 +65,7 @@ EThread::EThread(ThreadType att, int ani
   ethreads_to_be_signalled = (EThread **) xmalloc(MAX_EVENT_THREADS * sizeof(EThread *));
   memset((char *) ethreads_to_be_signalled, 0, MAX_EVENT_THREADS * sizeof(EThread *));
   memset(thread_private, 0, PER_THREAD_DATA);
+  thread_stats_mutex = new_ProxyMutex();
 #ifdef HAVE_EVENTFD
   evfd = eventfd(0, O_NONBLOCK | FD_CLOEXEC);
   if (evfd < 0) {
@@ -98,6 +100,7 @@ EThread::EThread(ThreadType att, Event *
 {
   ink_assert(att == DEDICATED);
   memset(thread_private, 0, PER_THREAD_DATA);
+  thread_stats_mutex = new_ProxyMutex();
 }
 
 

Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Sat May 15 03:31:38 2010
@@ -57,6 +57,8 @@
 //#include "MixtAPIInternal.h"
 #include "api/ts/InkAPIaaa.h"
 #include "FetchSM.h"
+#include "StatSystemV2.h"
+#include "HttpDebugNames.h"
 
 /****************************************************************
  *  IMPORTANT - READ ME
@@ -1041,6 +1043,31 @@ INKContInternal::handle_event_count(int 
   }
 }
 
+void INKContInternal::setName(const char *name) {
+    cont_name = name;
+    
+    cont_time_stats.resize((int)(INK_HTTP_LAST_HOOK + 1));
+    cont_calls.resize((int)(INK_HTTP_LAST_HOOK + 1));
+    
+    for(INKHttpHookID cur_hook_id = INK_HTTP_READ_REQUEST_HDR_HOOK; cur_hook_id <= INK_HTTP_LAST_HOOK; cur_hook_id = INKHttpHookID(cur_hook_id+1)) {
+        std::string stat_base = "cont." + cont_name + "." + HttpDebugNames::get_api_hook_name(cur_hook_id);
+        cont_time_stats[cur_hook_id].init(stat_base + ".time_spent", 64000);
+        
+        StatSystemV2::registerStat((stat_base + ".calls").c_str(), &cont_calls[cur_hook_id]);
+    }
+    stats_enabled = true;
+}
+
+const char *INKContInternal::getName() {
+    return cont_name.c_str();
+}
+
+void INKContInternal::statCallsMade(INKHttpHookID hook_id) {
+    if(cont_name == "")
+        return;
+    StatSystemV2::increment(cont_calls[hook_id]);
+}
+
 int
 INKContInternal::handle_event(int event, void *edata)
 {
@@ -7187,6 +7214,90 @@ INKStatIncrement(INKStat the_stat)
   return INK_SUCCESS;
 }
 
+INKReturnCode
+INKStatCreateV2(
+    const char *the_name,
+    uint32_t *stat_num)
+{
+    if(StatSystemV2::registerStat(the_name, stat_num)) {
+        return INK_SUCCESS;
+    }
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatIncrementV2(
+    uint32_t stat_num,
+    INK64 inc_by)
+{
+    if(StatSystemV2::increment(stat_num, inc_by)) {
+        return INK_SUCCESS;
+    }
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatIncrementByNameV2(
+    const char *stat_name,
+    INK64 inc_by)
+{
+    if(StatSystemV2::increment(stat_name, inc_by)) {
+        return INK_SUCCESS;
+    }
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatDecrementV2(
+    uint32_t stat_num,
+    INK64 dec_by)
+{
+    return INKStatIncrementV2(stat_num, (-1)*dec_by);
+}
+
+INKReturnCode
+INKStatDecrementByNameV2(
+    const char *stat_name,
+    INK64 dec_by)
+{
+    return INKStatIncrementByNameV2(stat_name, (-1)*dec_by);
+}
+
+INKReturnCode
+INKStatGetCurrentV2(
+    uint32_t stat_num, INK64 *stat_val)
+{
+    if(StatSystemV2::get_current(stat_num, stat_val))
+        return INK_SUCCESS;
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatGetCurrentByNameV2(
+    const char *stat_name, INK64 *stat_val)
+{
+    if(StatSystemV2::get_current(stat_name, stat_val))
+        return INK_SUCCESS;
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatGetV2(
+    uint32_t stat_num, INK64 *stat_val)
+{
+    if(StatSystemV2::get(stat_num, stat_val))
+        return INK_SUCCESS;
+    return INK_ERROR;
+}
+
+INKReturnCode
+INKStatGetByNameV2(
+    const char *stat_name, INK64 *stat_val)
+{
+    if(StatSystemV2::get(stat_name, stat_val))
+        return INK_SUCCESS;
+    return INK_ERROR;
+}
 
 INKReturnCode
 INKStatIntGet(INKStat the_stat, INK64 * value)

Modified: trafficserver/traffic/trunk/proxy/Main.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Main.cc?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Main.cc (original)
+++ trafficserver/traffic/trunk/proxy/Main.cc Sat May 15 03:31:38 2010
@@ -102,6 +102,8 @@ extern "C" int plock(int);
 
 #include "XmlUtils.h"
 
+#include "StatSystemV2.h"
+
 #ifdef HAVE_PROFILER
 #include <google/profiler.h>
 #endif
@@ -1681,6 +1683,42 @@ change_uid_gid(const char *user)
 #endif
 }
 
+void init_stat_collector()
+{
+    static int stat_collection_interval;
+    static int stat_collector_port;
+    static int max_stats_allowed = 0;
+    static int num_stats_estimate = 0;
+
+    static int temp = 0;
+    // Read config variables
+    TS_ReadConfigInteger(stat_collection_interval, "proxy.config.stat_collector.interval");
+    TS_ReadConfigInteger(stat_collector_port, "proxy.config.stat_collector.port");
+    TS_ReadConfigInteger(max_stats_allowed, "proxy.config.stat_systemV2.max_stats_allowed");
+    TS_ReadConfigInteger(num_stats_estimate, "proxy.config.stat_systemV2.num_stats_estimate");
+    TS_ReadConfigInteger(temp, "proxy.config.cache.threads_per_disk");
+
+    // Set to default if not defined in config file
+    if(!stat_collector_port) {
+        stat_collector_port = 8091;
+    }
+    if(!stat_collection_interval) {
+        stat_collection_interval = 600;
+    }
+
+    if(max_stats_allowed) {
+        StatSystemV2::setMaxStatsAllowed((uint32_t)max_stats_allowed);
+    }
+
+    if(num_stats_estimate) {
+        StatSystemV2::setNumStatsEstimate((uint32_t)num_stats_estimate);
+    }
+    StatSystemV2::init();
+    
+    StatCollectorContinuation::setStatCommandPort(stat_collector_port);
+    eventProcessor.schedule_every(NEW (new StatCollectorContinuation()),
+                                  HRTIME_SECONDS(stat_collection_interval), ET_CALL);
+}
 
 
 //
@@ -1890,6 +1928,9 @@ main(int argc, char **argv)
   ink_split_dns_init(makeModuleVersion(1, 0, PRIVATE_MODULE_HEADER));
   eventProcessor.start(num_of_net_threads);
 
+  // Must be called after starting event processor
+  init_stat_collector();
+
   int use_separate_thread = 0;
   int num_remap_threads = 1;
   TS_ReadConfigInteger(use_separate_thread, "proxy.config.remap.use_remap_processor");

Modified: trafficserver/traffic/trunk/proxy/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Makefile.am?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/Makefile.am Sat May 15 03:31:38 2010
@@ -143,6 +143,8 @@ traffic_server_SOURCES = \
   StatPages.h \
   StatSystem.cc \
   StatSystem.h \
+  StatSystemV2.cc \
+  StatTypes.cc \
   TestHook.cc \
   Transform.cc \
   Transform.h \
@@ -191,6 +193,8 @@ traffic_logcat_LDADD = \
   ControlBase.o \
   ControlMatcher.o CacheControl.o  \
   StatSystem.o \
+  StatSystemV2.o \
+  StatTypes.o \
   CacheInspectorAllow.o \
   ReverseProxy.o \
   ProxyConfig.o \
@@ -252,6 +256,8 @@ traffic_logstats_LDADD = \
   ControlMatcher.o \
   CacheControl.o  \
   StatSystem.o \
+  StatSystemV2.o \
+  StatTypes.o \
   CacheInspectorAllow.o \
   ReverseProxy.o \
   ProxyConfig.o \
@@ -314,6 +320,8 @@ traffic_sac_LDADD = \
   ControlMatcher.o \
   CacheControl.o \
   StatSystem.o \
+  StatSystemV2.o \
+  StatTypes.o \
   CacheInspectorAllow.o \
   ReverseProxy.o \
   ProxyConfig.o \
@@ -379,6 +387,8 @@ libTrafficServerStandalone_a_SOURCES = \
   DiagsConfig.cc \
   StatPages.cc \
   StatSystem.cc \
+  StatSystemV2.cc \
+  StatTypes.cc \
   AbstractBuffer.cc \
   Initialize.cc
 

Modified: trafficserver/traffic/trunk/proxy/api/ts/InkAPIPrivateIOCore.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/InkAPIPrivateIOCore.h?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/InkAPIPrivateIOCore.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/InkAPIPrivateIOCore.h Sat May 15 03:31:38 2010
@@ -34,6 +34,10 @@
 #include "P_Net.h"
 #endif
 
+#include <string>
+#include <vector>
+#include "StatTypes.h"
+
 enum INKContInternalMagic_t
 {
   INKCONT_INTERN_MAGIC_ALIVE = 0x00009631,
@@ -51,6 +55,10 @@ public:
 
   void handle_event_count(int event);
   int handle_event(int event, void *edata);
+  void setName(const char *name);
+  const char *getName();
+  void statCallsMade(INKHttpHookID hook_id);
+  bool isStatsEnabled() { return stats_enabled; }
 
 public:
   void *mdata;
@@ -61,6 +69,12 @@ public:
   int m_deleted;
   //INKqa07670: Nokia memory leak bug fix
   INKContInternalMagic_t m_free_magic;
+
+  std::string cont_name;
+  std::vector<HistogramStats> cont_time_stats;
+  std::vector<uint32_t> cont_calls;
+  bool stats_enabled;
+
 };
 
 

Modified: trafficserver/traffic/trunk/proxy/api/ts/ts.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/ts.h?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/ts.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/ts.h Sat May 15 03:31:38 2010
@@ -31,6 +31,7 @@
 #define __INK_API_H__
 
 #include <sys/types.h>
+#include <stdint.h>
 
 #define inkapi
 #define inkexp
@@ -2454,6 +2455,17 @@ extern "C"
   inkapi INKStat INKStatCoupledLocalAdd(INKCoupledStat local_copy, const char *the_name, INKStatTypes the_type);
   inkapi INKReturnCode INKStatsCoupledUpdate(INKCoupledStat local_copy);
 
+  /* new stat system */
+  inkapi INKReturnCode     INKStatCreateV2(const char *name, uint32_t *stat_num);
+  inkapi INKReturnCode     INKStatIncrementV2(uint32_t stat_num, INK64 inc_by);
+  inkapi INKReturnCode     INKStatIncrementByNameV2(const char *stat_name, INK64 inc_by);
+  inkapi INKReturnCode     INKStatDecrementV2(uint32_t stat_num, INK64 dec_by);
+  inkapi INKReturnCode     INKStatDecrementByNameV2(const char *stat_name, INK64 dec_by);
+  inkapi INKReturnCode     INKStatGetCurrentV2(uint32_t stat_num, INK64 *stat_val);
+  inkapi INKReturnCode     INKStatGetCurrentByNameV2(const char *stat_name, INK64 *stat_val);
+  inkapi INKReturnCode     INKStatGetV2(uint32_t stat_num, INK64 *stat_val);
+  inkapi INKReturnCode     INKStatGetByNameV2(const char *stat_name, INK64 *stat_val);
+
   // --------------------------------------------------------------------------
   // tracing api
 

Modified: trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpSM.cc Sat May 15 03:31:38 2010
@@ -37,7 +37,7 @@
 #include "PluginVC.h"
 #include "ReverseProxy.h"
 #include "RemapProcessor.h"
-
+#include "StatSystemV2.h"
 
 #ifdef USE_NCA
 #include "NcaProcessor.h"
@@ -343,6 +343,7 @@ server_response_hdr_bytes(0), server_res
 client_response_hdr_bytes(0), client_response_body_bytes(0),
 pushed_response_hdr_bytes(0), pushed_response_body_bytes(0),
 hooks_set(0), cur_hook_id(INK_HTTP_LAST_HOOK), cur_hook(NULL),
+prev_hook_start_time(0), prev_hook_stats_enabled(false),
 cur_hooks(0), callout_state(HTTP_API_NO_CALLOUT), terminate_sm(false), kill_this_async_done(false)
 {
   static int scatter_init = 0;
@@ -1453,6 +1454,25 @@ HttpSM::state_api_callout(int event, voi
         APIHook *hook = cur_hook;
         cur_hook = cur_hook->next();
 
+        // Do per plugin stats
+        // Increment calls made to plugin
+        hook->m_cont->statCallsMade(cur_hook_id);
+
+        // Stat time spent in previous plugin
+        INK64 curr_time = INKhrtime();
+        if(prev_hook_stats_enabled && prev_hook_start_time) {
+          INK64 time_in_plugin_ms = (curr_time - prev_hook_start_time)/1000000;
+          prev_hook_stats.inc(time_in_plugin_ms);
+          Debug("http", "[%b64d] Time spent in plugin %s = %b64d", 
+                sm_id, HttpDebugNames::get_api_hook_name(cur_hook_id), time_in_plugin_ms);
+        }
+
+        // store time and plugin info before invoking it
+        prev_hook_start_time = curr_time;
+        prev_hook_stats_enabled = hook->m_cont->isStatsEnabled();
+        if(prev_hook_stats_enabled)
+          prev_hook_stats = hook->m_cont->cont_time_stats[cur_hook_id];
+
         hook->invoke(INK_EVENT_HTTP_READ_REQUEST_HDR + cur_hook_id, this);
 
         if (plugin_lock) {
@@ -1527,6 +1547,20 @@ HttpSM::state_api_callout(int event, voi
   case API_RETURN_CONTINUE:
     if (t_state.api_next_action == HttpTransact::HTTP_API_SEND_REPONSE_HDR)
       do_redirect();
+
+    // Do per plugin stats
+    // Handle last plugin on current state
+    if(prev_hook_stats_enabled && prev_hook_start_time) {
+      INK64 time_in_plugin_ms = (INKhrtime() - prev_hook_start_time)/1000000;
+      Debug("http", "[%b64d] Last plugin : Time spent : %s %b64d", 
+            sm_id, HttpDebugNames::get_api_hook_name(cur_hook_id), time_in_plugin_ms);
+      prev_hook_stats.inc(time_in_plugin_ms);
+    }
+    
+    // Get ready for next state
+    prev_hook_stats_enabled = false;
+    prev_hook_start_time = 0;
+
     handle_api_return();
     break;
   case API_RETURN_DEFERED_CLOSE:

Modified: trafficserver/traffic/trunk/proxy/http2/HttpSM.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http2/HttpSM.h?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http2/HttpSM.h (original)
+++ trafficserver/traffic/trunk/proxy/http2/HttpSM.h Sat May 15 03:31:38 2010
@@ -40,6 +40,7 @@
 #include "HttpTunnel.h"
 #include "InkAPIInternal.h"
 #include "StatSystem.h"
+#include "StatTypes.h"
 #include "HttpClientSession.h"
 //#include "AuthHttpAdapter.h"
 
@@ -495,6 +496,14 @@ public:
 protected:
   INKHttpHookID cur_hook_id;
   APIHook *cur_hook;
+
+  //
+  // Continuation time keeper
+  INK64 prev_hook_start_time;
+
+  bool prev_hook_stats_enabled;
+  HistogramStats prev_hook_stats;
+  
   int cur_hooks;
   HttpApiState_t callout_state;
 

Modified: trafficserver/traffic/trunk/proxy/mgmt2/RecordsConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/RecordsConfig.cc?rev=944551&r1=944550&r2=944551&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/RecordsConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/RecordsConfig.cc Sat May 15 03:31:38 2010
@@ -4140,6 +4140,12 @@ RecordElement RecordsConfig[] = {
   {CONFIG, "proxy.config.prefetch.redirection", "", INK_INT, "0", RU_NULL, RR_NULL, RC_NULL, NULL, RA_NULL}
   ,
 
+  // StatSystemV2 config
+  {CONFIG, "proxy.config.stat_collector.interval", "", INK_INT, "600", RU_NULL, RR_NULL, RC_NULL, NULL, RA_NULL},
+  {CONFIG, "proxy.config.stat_collector.port", "", INK_INT, "8091", RU_NULL, RR_NULL, RC_NULL, NULL, RA_NULL},
+  {CONFIG, "proxy.config.stat_systemV2.max_stats_allowed", "", INK_INT, "0", RU_NULL, RR_NULL, RC_NULL, NULL, RA_NULL},
+  {CONFIG, "proxy.config.stat_systemV2.num_stats_estimate", "", INK_INT, "0", RU_NULL, RR_NULL, RC_NULL, NULL, RA_NULL},
+
   //############
   //#
   //# Eric's super cool remap processor