trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject trafficserver git commit: TS-153: Dynamic keep-alive timeouts Updates after a code review with AMC and more testing
Date Fri, 23 Jan 2015 01:21:47 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 729cb8003 -> ab3fec0a8


TS-153: Dynamic keep-alive timeouts
Updates after a code review with AMC and more testing


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

Branch: refs/heads/master
Commit: ab3fec0a88aba5bf8da5078ea0ab326e4fd61988
Parents: 729cb80
Author: Bryan Call <bcall@apache.org>
Authored: Thu Jan 22 17:19:53 2015 -0800
Committer: Bryan Call <bcall@apache.org>
Committed: Thu Jan 22 17:19:53 2015 -0800

----------------------------------------------------------------------
 cmd/traffic_top/stats.h          |  4 +--
 iocore/net/UnixNet.cc            | 68 ++++++++++++++++++++++++-----------
 iocore/net/UnixNetVConnection.cc |  2 +-
 3 files changed, 51 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab3fec0a/cmd/traffic_top/stats.h
----------------------------------------------------------------------
diff --git a/cmd/traffic_top/stats.h b/cmd/traffic_top/stats.h
index 5c9c72b..64dc5bf 100644
--- a/cmd/traffic_top/stats.h
+++ b/cmd/traffic_top/stats.h
@@ -252,9 +252,9 @@ public:
             (*_stats)[key] = strValue;
           } else {
             if (TSRecordGetInt(item.name, &value) != TS_ERR_OKAY) {
-              fprintf(stderr, "Error getting stat: %s\n", item.name);
+              fprintf(stderr, "Error getting stat: %s when calling TSRecordGetInt() failed:
file \"%s\", line %d\n\n",
+                  item.name, __FILE__, __LINE__);
             }
-            assert(TSRecordGetInt(item.name, &value) == TS_ERR_OKAY);
             string key = item.name;
             char buffer[32];
             sprintf(buffer, "%" PRId64, value);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab3fec0a/iocore/net/UnixNet.cc
----------------------------------------------------------------------
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index 42bac73..0904b67 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -35,25 +35,32 @@ extern "C" void fd_reify(struct ev_loop *);
 
 
 #ifndef INACTIVITY_TIMEOUT
+int update_cop_config(const char *name, RecDataT data_type, RecData data, void *cookie);
+
 // INKqa10496
 // One Inactivity cop runs on each thread once every second and
 // loops through the list of NetVCs and calls the timeouts
 class InactivityCop : public Continuation {
 public:
-  InactivityCop(ProxyMutex *m):Continuation(m), default_inactivity_timeout(0), total_connections(0)
{
+  InactivityCop(ProxyMutex *m):Continuation(m), default_inactivity_timeout(0), total_connections_in(0),
+  max_connections_in(0), connections_per_thread_in(0) {
     SET_HANDLER(&InactivityCop::check_inactivity);
     REC_ReadConfigInteger(default_inactivity_timeout, "proxy.config.net.default_inactivity_timeout");
     Debug("inactivity_cop", "default inactivity timeout is set to: %d", default_inactivity_timeout);
+    REC_ReadConfigInt32(max_connections_in, "proxy.config.net.max_connections_in");
+    RecRegisterConfigUpdateCb("proxy.config.net.max_connections_in", update_cop_config, (void
*)this);
   }
   int check_inactivity(int event, Event *e) {
     (void) event;
     ink_hrtime now = ink_get_hrtime();
     NetHandler &nh = *get_NetHandler(this_ethread());
-    total_connections = 0;
+    total_connections_in = 0;
     // Copy the list and use pop() to catch any closes caused by callbacks.
     forl_LL(UnixNetVConnection, vc, nh.open_list) {
       if (vc->thread == this_ethread()) {
-        ++total_connections;
+        if (vc->from_accept_thread == true) {
+          ++total_connections_in;
+        }
         nh.cop_list.push(vc);
       }
     }
@@ -98,38 +105,53 @@ public:
 
     return 0;
   }
+  void set_max_connections(const int32_t x) { max_connections_in = x; }
+  void set_connections_pre_thread(const int32_t x) { connections_per_thread_in = x; }
 private:
   void keep_alive_lru(NetHandler &nh, ink_hrtime now, Event *e);
   int default_inactivity_timeout;  // only used when one is not set for some bad reason
-  int total_connections;
+  int32_t total_connections_in;
+  int32_t max_connections_in;
+  int32_t connections_per_thread_in;
 };
 
+int
+update_cop_config(const char *name, RecDataT data_type, RecData data, void *cookie)
+{
+  if ((cookie != NULL) && (strcmp(name, "proxy.config.net.max_connections_in") ==
0)) {
+    Debug("inactivity_cop_dynamic", "proxy.config.net.max_connections_in change: %" PRId64,
data.rec_int);
+    InactivityCop *cop = static_cast<InactivityCop*>(cookie);
+    cop->set_max_connections(data.rec_int);
+    cop->set_connections_pre_thread(0);
+  }
+  return REC_ERR_OKAY;
+}
+
 void InactivityCop::keep_alive_lru(NetHandler &nh, const ink_hrtime now, Event *e)
 {
-  // get the configuration value for the maximum incoming connections and check to see if
it is set
-  int32_t connections_per_thread = 0;
-  REC_ReadConfigInt32(connections_per_thread, "proxy.config.net.max_connections_in");
-  if (connections_per_thread <= 0) {
-    Debug("inactivity_cop_dynamic", "dynamic keep-alive not configured");
+  // maximum incoming connections is set to 0 then the feature is disabled
+  if (max_connections_in == 0) {
     return;
   }
 
-  // figure out the number of threads and calculate the number of connections per thread
-  const int event_threads = eventProcessor.n_threads_for_type[ET_NET];
-  const int ssl_threads = (ET_NET == SSLNetProcessor::ET_SSL) ? 0 :
-      eventProcessor.n_threads_for_type[SSLNetProcessor::ET_SSL];
-  connections_per_thread = connections_per_thread / (event_threads + ssl_threads);
+  if (connections_per_thread_in == 0) {
+    // figure out the number of threads and calculate the number of connections per thread
+    const int event_threads = eventProcessor.n_threads_for_type[ET_NET];
+    const int ssl_threads = (ET_NET == SSLNetProcessor::ET_SSL) ? 0 :
+        eventProcessor.n_threads_for_type[SSLNetProcessor::ET_SSL];
+    connections_per_thread_in = max_connections_in / (event_threads + ssl_threads);
+  }
 
   // calculate how many connections to close
-  int32_t to_process = total_connections - connections_per_thread;
+  int32_t to_process = total_connections_in - connections_per_thread_in;
   if (to_process <= 0) {
     return;
   }
   to_process = min((int32_t)nh.keep_alive_lru_size, to_process);
 
-  Debug("inactivity_cop_dynamic", "max cons: %d active: %d idle: %d process: %d net threads:
%d ssl threads: %d"
-        "net type: %d ssl type: %d", connections_per_thread, total_connections - nh.keep_alive_lru_size,
-        nh.keep_alive_lru_size, to_process, event_threads, ssl_threads, ET_NET, SSLNetProcessor::ET_SSL);
+  Debug("inactivity_cop_dynamic", "max cons: %d active: %d idle: %d process: %d"
+        " net type: %d ssl type: %d", connections_per_thread_in, total_connections_in - nh.keep_alive_lru_size,
+        nh.keep_alive_lru_size, to_process, ET_NET, SSLNetProcessor::ET_SSL);
 
   // loop over the non-active connections and try to close them
   UnixNetVConnection *vc = nh.keep_alive_list.head;
@@ -140,8 +162,13 @@ void InactivityCop::keep_alive_lru(NetHandler &nh, const ink_hrtime
now, Event *
   int total_idle_count = 0;
   for (int32_t i = 0; i < to_process && vc != NULL; ++i, vc = vc_next) {
     vc_next = vc->keep_alive_link.next;
-    if (vc->thread != this_ethread())
+    if (vc->thread != this_ethread()) {
       continue;
+    }
+    MUTEX_TRY_LOCK(lock, vc->mutex, this_ethread());
+    if (!lock.is_locked()) {
+      continue;
+    }
     ink_hrtime diff = (now - (vc->next_inactivity_timeout_at - vc->inactivity_timeout_in))
/ HRTIME_SECOND;
     if (diff > 0) {
       total_idle_time += diff;
@@ -166,7 +193,8 @@ void InactivityCop::keep_alive_lru(NetHandler &nh, const ink_hrtime
now, Event *
 
   if (total_idle_count > 0) {
     Debug("inactivity_cop_dynamic", "max cons: %d active: %d idle: %d already closed: %d,
close event: %d"
-          "mean idle: %d\n", connections_per_thread, total_connections - nh.keep_alive_lru_size,
+          " mean idle: %d\n", connections_per_thread_in,
+          total_connections_in - nh.keep_alive_lru_size - closed - handle_event,
           nh.keep_alive_lru_size, closed, handle_event, total_idle_time / total_idle_count);
   }
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab3fec0a/iocore/net/UnixNetVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index bbe0c14..0319c8e 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -125,6 +125,7 @@ close_UnixNetVConnection(UnixNetVConnection *vc, EThread *t)
     nh->write_enable_list.remove(vc);
     vc->write.in_enabled_list = 0;
   }
+  vc->remove_from_keep_alive_lru();
   vc->free(t);
 }
 
@@ -617,7 +618,6 @@ UnixNetVConnection::do_io_close(int alerrno /* = -1 */ )
   else
     closed = -1;
 
-  remove_from_keep_alive_lru();
   if (close_inline)
     close_UnixNetVConnection(this, t);
 }


Mime
View raw message