This is an automated email from the ASF dual-hosted git repository.

vmamidi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e9e4ed  Throttling results in tight loop if there are no new 
connections
1e9e4ed is described below

commit 1e9e4ed3be52dc8ef2433baba6816df4eb032055
Author: Vijay Mamidi <[email protected]>
AuthorDate: Tue Apr 23 10:12:17 2019 +0800

    Throttling results in tight loop if there are no new connections
---
 iocore/net/UnixNetAccept.cc | 42 ++++++++----------------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 2a2c2f7..a936c5e 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -43,29 +43,6 @@ safe_delay(int msec)
   socketManager.poll(nullptr, 0, msec);
 }
 
-static int
-drain_throttled_accepts(NetAccept *na)
-{
-  struct pollfd afd;
-  Connection con[THROTTLE_AT_ONCE];
-
-  afd.fd     = na->server.fd;
-  afd.events = POLLIN;
-
-  // Try to close at most THROTTLE_AT_ONCE accept requests
-  // Stop if there is nothing waiting
-  int n = 0;
-  for (; n < THROTTLE_AT_ONCE && socketManager.poll(&afd, 1, 0) > 0; n++) {
-    int res = 0;
-    if ((res = na->server.accept(&con[n])) < 0) {
-      return res;
-    }
-    con[n].close();
-  }
-  // Return the number of accept cases we closed
-  return n;
-}
-
 //
 // General case network connection accept code
 //
@@ -307,18 +284,7 @@ NetAccept::do_blocking_accept(EThread *t)
   // do-while for accepting all the connections
   // added by YTS Team, yamsat
   do {
-    // Throttle accepts
-    while (!opt.backdoor && check_net_throttle(ACCEPT)) {
-      check_throttle_warning(ACCEPT);
-      int num_throttled = drain_throttled_accepts(this);
-      if (num_throttled < 0) {
-        goto Lerror;
-      }
-      NET_SUM_DYN_STAT(net_connections_throttled_in_stat, num_throttled);
-    }
-
     if ((res = server.accept(&con)) < 0) {
-    Lerror:
       int seriousness = accept_error_seriousness(res);
       if (seriousness >= 0) { // not so bad
         if (!seriousness) {   // bad enough to warn about
@@ -334,6 +300,14 @@ NetAccept::do_blocking_accept(EThread *t)
       }
       return -1;
     }
+    // check for throttle
+    if (!opt.backdoor && check_net_throttle(ACCEPT)) {
+      check_throttle_warning(ACCEPT);
+      // close the connection as we are in throttle state
+      con.close();
+      NET_SUM_DYN_STAT(net_connections_throttled_in_stat, 1);
+      continue;
+    }
 
     if (TSSystemState::is_event_system_shut_down()) {
       return -1;

Reply via email to