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

bcall pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new 5dee9ece5f Update accept thread configuration changes from #10687 
applied to 9.2.x (#10744)
5dee9ece5f is described below

commit 5dee9ece5f69e57c347d425be26789d50eba6fc8
Author: Nathan Wang <wang.natha...@gmail.com>
AuthorDate: Mon Jan 29 15:31:27 2024 -0700

    Update accept thread configuration changes from #10687 applied to 9.2.x 
(#10744)
    
    * cherry pick changes from #10687 to 9.2.x
    
    * removed an unused nethandler instance
    
    * another unused variable
    
    ---------
    
    Co-authored-by: Nathan Wang <nathan_c_w...@apple.com>
---
 iocore/net/P_UnixNet.h      | 12 ++++++++++--
 iocore/net/UnixNet.cc       | 15 +++++++++++----
 iocore/net/UnixNetAccept.cc |  9 +++------
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
index d5b68bf787..bf8acd4031 100644
--- a/iocore/net/P_UnixNet.h
+++ b/iocore/net/P_UnixNet.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include <atomic>
+
 #include <bitset>
 
 #include "tscore/ink_platform.h"
@@ -281,7 +283,6 @@ public:
     uint32_t transaction_no_activity_timeout_in = 0;
     uint32_t keep_alive_no_activity_timeout_in  = 0;
     uint32_t default_inactivity_timeout         = 0;
-    uint32_t additional_accepts                 = 0;
 
     /** Return the address of the first value in this struct.
 
@@ -328,7 +329,7 @@ public:
   void remove_from_keep_alive_queue(NetEvent *ne);
   bool add_to_active_queue(NetEvent *ne);
   void remove_from_active_queue(NetEvent *ne);
-  int get_additional_accepts();
+  static int get_additional_accepts();
 
   /// Per process initialization logic.
   static void init_for_process();
@@ -386,6 +387,13 @@ public:
   NetHandler();
 
 private:
+  // The following settings are used potentially by accept threads. These are
+  // shared across threads via std::atomic rather than being pulled through a
+  // TS_EVENT_MGMT_UPDATE event like with the Config settings above because
+  // accept threads are not always on a standard NET thread with a NetHandler
+  // that has TS_EVENT_MGMT_UPDATE handling logic.
+  static std::atomic<uint32_t> additional_accepts;
+
   void _close_ne(NetEvent *ne, ink_hrtime now, int &handle_event, int &closed, 
int &total_idle_time, int &total_idle_count);
 
   /// Static method used as the callback for runtime configuration updates.
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index e1dca3ce39..b5688d5356 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -25,6 +25,8 @@
 
 using namespace std::literals;
 
+std::atomic<uint32_t> NetHandler::additional_accepts{0};
+
 ink_hrtime last_throttle_warning;
 ink_hrtime last_shedding_warning;
 int net_connections_throttle;
@@ -295,7 +297,7 @@ NetHandler::update_nethandler_config(const char *str, 
RecDataT, RecData data, vo
     updated_member = &NetHandler::global_config.default_inactivity_timeout;
     Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to 
%" PRId64, data.rec_int);
   } else if (name == "proxy.config.net.additional_accepts"sv) {
-    updated_member = &NetHandler::global_config.additional_accepts;
+    NetHandler::additional_accepts.store(data.rec_int, 
std::memory_order_relaxed);
     Debug("net_queue", "proxy.config.net.additional_accepts updated to %" 
PRId64, data.rec_int);
   }
 
@@ -332,7 +334,12 @@ NetHandler::init_for_process()
   REC_ReadConfigInt32(global_config.transaction_no_activity_timeout_in, 
"proxy.config.net.transaction_no_activity_timeout_in");
   REC_ReadConfigInt32(global_config.keep_alive_no_activity_timeout_in, 
"proxy.config.net.keep_alive_no_activity_timeout_in");
   REC_ReadConfigInt32(global_config.default_inactivity_timeout, 
"proxy.config.net.default_inactivity_timeout");
-  REC_ReadConfigInt32(global_config.additional_accepts, 
"proxy.config.net.additional_accepts");
+
+  // Atomic configurations.
+  uint32_t val = 0;
+
+  REC_ReadConfigInt32(val, "proxy.config.net.additional_accepts");
+  additional_accepts.store(val, std::memory_order_relaxed);
 
   RecRegisterConfigUpdateCb("proxy.config.net.max_connections_in", 
update_nethandler_config, nullptr);
   RecRegisterConfigUpdateCb("proxy.config.net.max_requests_in", 
update_nethandler_config, nullptr);
@@ -350,7 +357,7 @@ NetHandler::init_for_process()
   Debug("net_queue", "proxy.config.net.keep_alive_no_activity_timeout_in 
updated to %d",
         global_config.keep_alive_no_activity_timeout_in);
   Debug("net_queue", "proxy.config.net.default_inactivity_timeout updated to 
%d", global_config.default_inactivity_timeout);
-  Debug("net_queue", "proxy.config.net.additional_accepts updated to %d", 
global_config.additional_accepts);
+  Debug("net_queue", "proxy.config.net.additional_accepts updated to %d", 
additional_accepts.load(std::memory_order_relaxed));
 }
 
 //
@@ -792,6 +799,6 @@ NetHandler::remove_from_active_queue(NetEvent *ne)
 int
 NetHandler::get_additional_accepts()
 {
-  int config_value = config.additional_accepts + 1;
+  int config_value = additional_accepts.load(std::memory_order_relaxed) + 1;
   return (config_value > 0 ? config_value : INT32_MAX - 1);
 }
\ No newline at end of file
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 5545ee35e9..78a8ddd623 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -50,8 +50,7 @@ net_accept(NetAccept *na, void *ep, bool blockable)
   UnixNetVConnection *vc = nullptr;
   Connection con;
 
-  EThread *t             = e->ethread;
-  int additional_accepts = get_NetHandler(t)->get_additional_accepts();
+  int additional_accepts = NetHandler::get_additional_accepts();
 
   if (!blockable) {
     if (!MUTEX_TAKE_TRY_LOCK(na->action_->mutex, e->ethread)) {
@@ -299,7 +298,7 @@ NetAccept::do_blocking_accept(EThread *t)
   con.sock_type = SOCK_STREAM;
 
   int count              = 0;
-  int additional_accepts = get_NetHandler(t)->get_additional_accepts();
+  int additional_accepts = NetHandler::get_additional_accepts();
 
   // do-while for accepting all the connections
   // added by YTS Team, yamsat
@@ -441,9 +440,7 @@ NetAccept::acceptFastEvent(int event, void *ep)
 
   UnixNetVConnection *vc = nullptr;
   int count              = 0;
-  EThread *t             = e->ethread;
-  NetHandler *h          = get_NetHandler(t);
-  int additional_accepts = h->get_additional_accepts();
+  int additional_accepts = NetHandler::get_additional_accepts();
 
   do {
     socklen_t sz = sizeof(con.addr);

Reply via email to