You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2019/10/26 23:56:20 UTC
[trafficserver] branch 9.0.x updated (5cb5590 -> 7bd0a53)
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.
from 5cb5590 Upgrade warning about cachekey behavior
new e0af528 support for listening on all the net threads uses epollexclusive flag and soreuseport
new 7bd0a53 Fix the malformed threads table
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
doc/admin-guide/files/records.config.en.rst | 14 ++++++
iocore/net/Connection.cc | 14 +++++-
iocore/net/P_NetAccept.h | 1 +
iocore/net/P_UnixNet.h | 5 ++-
iocore/net/UnixNet.cc | 2 +
iocore/net/UnixNetAccept.cc | 70 ++++++++++++++++++-----------
iocore/net/UnixNetProcessor.cc | 7 ++-
mgmt/RecordsConfig.cc | 2 +
src/traffic_manager/traffic_manager.cc | 5 +++
9 files changed, 92 insertions(+), 28 deletions(-)
[trafficserver] 01/02: support for listening on all the net threads
uses epollexclusive flag and soreuseport
Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit e0af528971648a32fef038a4751556e9cfa3ff49
Author: Vijay Mamidi <vm...@apache.org>
AuthorDate: Sat Oct 12 21:45:25 2019 +0000
support for listening on all the net threads uses epollexclusive flag and soreuseport
(cherry picked from commit 4dc8dc7f787fcb484e85b6dcf646c189a74fb1b3)
---
doc/admin-guide/files/records.config.en.rst | 14 ++++++
iocore/net/Connection.cc | 14 +++++-
iocore/net/P_NetAccept.h | 1 +
iocore/net/P_UnixNet.h | 5 ++-
iocore/net/UnixNet.cc | 2 +
iocore/net/UnixNetAccept.cc | 70 ++++++++++++++++++-----------
iocore/net/UnixNetProcessor.cc | 7 ++-
mgmt/RecordsConfig.cc | 2 +
src/traffic_manager/traffic_manager.cc | 5 +++
9 files changed, 92 insertions(+), 28 deletions(-)
diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst
index ea7dfb8..f875519 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -317,11 +317,25 @@ Thread Variables
The number of threads |TS| will create if `proxy.config.exec_thread.autoconfig`
is set to ``0``, otherwise this option is ignored.
+.. ts:cv:: CONFIG proxy.config.exec_thread.listen INT 0
+
+ If enabled (``1``) all the exex_threads listen for incoming connections. `proxy.config.accept_threads`
+ should be disabled to enable this variable.
+
.. ts:cv:: CONFIG proxy.config.accept_threads INT 1
The number of accept threads. If disabled (``0``), then accepts will be done
in each of the worker threads.
+ ============== ================== ===================
+ accept_threads exec_thread.listen Effect
+ ============== ================== ===================
+ ``0`` ``0`` All worker threads accept new connections and share listen fd.
+ ``1`` ``0`` New conections are accepted on a dedicated accept thread and distributed to worker threads in round robin fashion.
+ ``0`` ``1`` All worker threads listen on the same port using SO_REUSEPORT.
+ Each thread has its own listen and new connections are accepted on all the threads.
+
+ By default, `proxy.config.accept_threads` is set to 1 and `proxy.config.exec_thread.listen` is set to 0.
.. ts:cv:: CONFIG proxy.config.thread.default.stacksize INT 1048576
Default thread stack size, in bytes, for all threads (default is 1 MB).
diff --git a/iocore/net/Connection.cc b/iocore/net/Connection.cc
index da7f530..99c1088 100644
--- a/iocore/net/Connection.cc
+++ b/iocore/net/Connection.cc
@@ -136,7 +136,8 @@ add_http_filter(int fd ATS_UNUSED)
int
Server::setup_fd_for_listen(bool non_blocking, const NetProcessor::AcceptOptions &opt)
{
- int res = 0;
+ int res = 0;
+ int listen_per_thread = 0;
ink_assert(fd != NO_FD);
@@ -212,6 +213,17 @@ Server::setup_fd_for_listen(bool non_blocking, const NetProcessor::AcceptOptions
if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, SOCKOPT_ON, sizeof(int))) < 0) {
goto Lerror;
}
+ REC_ReadConfigInteger(listen_per_thread, "proxy.config.exec_thread.listen");
+ if (listen_per_thread == 1) {
+ if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, SOCKOPT_ON, sizeof(int))) < 0) {
+ goto Lerror;
+ }
+#ifdef SO_REUSEPORT_LB
+ if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB, SOCKOPT_ON, sizeof(int))) < 0) {
+ goto Lerror;
+ }
+#endif
+ }
if ((opt.sockopt_flags & NetVCOptions::SOCK_OPT_NO_DELAY) &&
(res = safe_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, SOCKOPT_ON, sizeof(int))) < 0) {
diff --git a/iocore/net/P_NetAccept.h b/iocore/net/P_NetAccept.h
index aa136b0..db7ceb6 100644
--- a/iocore/net/P_NetAccept.h
+++ b/iocore/net/P_NetAccept.h
@@ -107,6 +107,7 @@ struct NetAccept : public Continuation {
virtual int acceptEvent(int event, void *e);
virtual int acceptFastEvent(int event, void *e);
+ virtual int accept_per_thread(int event, void *e);
int acceptLoopEvent(int event, Event *e);
void cancel();
diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h
index a29cd7f..91ccb6f 100644
--- a/iocore/net/P_UnixNet.h
+++ b/iocore/net/P_UnixNet.h
@@ -38,6 +38,9 @@
#define EVENTIO_ASYNC_SIGNAL 5
#if TS_USE_EPOLL
+#ifndef EPOLLEXCLUSIVE
+#define EPOLLEXCLUSIVE 0
+#endif
#ifdef USE_EDGE_TRIGGER_EPOLL
#define USE_EDGE_TRIGGER 1
#define EVENTIO_READ (EPOLLIN | EPOLLET)
@@ -592,7 +595,7 @@ EventIO::start(EventLoop l, int afd, Continuation *c, int e)
#if TS_USE_EPOLL
struct epoll_event ev;
memset(&ev, 0, sizeof(ev));
- ev.events = e;
+ ev.events = e | EPOLLEXCLUSIVE;
ev.data.ptr = this;
#ifndef USE_EDGE_TRIGGER
events = e;
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index c2eded5..7690077 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -524,6 +524,8 @@ NetHandler::waitForActivity(ink_hrtime timeout)
}
} else if (epd->type == EVENTIO_ASYNC_SIGNAL) {
net_signal_hook_callback(this->thread);
+ } else if (epd->type == EVENTIO_NETACCEPT) {
+ this->thread->schedule_imm(epd->data.c);
}
ev_next_event(pd, x);
}
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 3a452f6..9254d7f 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -201,15 +201,17 @@ NetAccept::init_accept(EThread *t)
t->schedule_every(this, period);
}
-void
-NetAccept::init_accept_per_thread()
+int
+NetAccept::accept_per_thread(int event, void *ep)
{
- int i, n;
+ int listen_per_thread = 0;
+ REC_ReadConfigInteger(listen_per_thread, "proxy.config.exec_thread.listen");
- ink_assert(opt.etype >= 0);
-
- if (do_listen(NON_BLOCKING)) {
- return;
+ if (listen_per_thread == 1) {
+ if (do_listen(NON_BLOCKING)) {
+ Fatal("[NetAccept::accept_per_thread]:error listenting on ports");
+ return -1;
+ }
}
if (accept_fn == net_accept) {
@@ -217,21 +219,38 @@ NetAccept::init_accept_per_thread()
} else {
SET_HANDLER((NetAcceptHandler)&NetAccept::acceptEvent);
}
+ PollDescriptor *pd = get_PollDescriptor(this_ethread());
+ if (this->ep.start(pd, this, EVENTIO_READ) < 0) {
+ Fatal("[NetAccept::accept_per_thread]:error starting EventIO");
+ return -1;
+ }
+ return 0;
+}
- period = -HRTIME_MSECONDS(net_accept_period);
- n = eventProcessor.thread_group[opt.etype]._count;
+void
+NetAccept::init_accept_per_thread()
+{
+ int i, n;
+ int listen_per_thread = 0;
- for (i = 0; i < n; i++) {
- NetAccept *a = (i < n - 1) ? clone() : this;
- EThread *t = eventProcessor.thread_group[opt.etype]._thread[i];
- PollDescriptor *pd = get_PollDescriptor(t);
+ ink_assert(opt.etype >= 0);
+ REC_ReadConfigInteger(listen_per_thread, "proxy.config.exec_thread.listen");
- if (a->ep.start(pd, a, EVENTIO_READ) < 0) {
- Warning("[NetAccept::init_accept_per_thread]:error starting EventIO");
+ if (listen_per_thread == 0) {
+ if (do_listen(NON_BLOCKING)) {
+ Fatal("[NetAccept::accept_per_thread]:error listenting on ports");
+ return;
}
+ }
+
+ SET_HANDLER((NetAcceptHandler)&NetAccept::accept_per_thread);
+ n = eventProcessor.thread_group[opt.etype]._count;
- a->mutex = get_NetHandler(t)->mutex;
- t->schedule_every(a, period);
+ for (i = 0; i < n; i++) {
+ NetAccept *a = (i < n - 1) ? clone() : this;
+ EThread *t = eventProcessor.thread_group[opt.etype]._thread[i];
+ a->mutex = get_NetHandler(t)->mutex;
+ t->schedule_imm(a);
}
}
@@ -401,16 +420,18 @@ NetAccept::acceptFastEvent(int event, void *ep)
int loop = accept_till_done;
do {
- if (!opt.backdoor && check_net_throttle(ACCEPT)) {
- ifd = NO_FD;
- return EVENT_CONT;
- }
-
socklen_t sz = sizeof(con.addr);
int fd = socketManager.accept4(server.fd, &con.addr.sa, &sz, SOCK_NONBLOCK | SOCK_CLOEXEC);
con.fd = fd;
if (likely(fd >= 0)) {
+ // check for throttle
+ if (!opt.backdoor && check_net_throttle(ACCEPT)) {
+ // close the connection as we are in throttle state
+ con.close();
+ NET_SUM_DYN_STAT(net_connections_throttled_in_stat, 1);
+ continue;
+ }
Debug("iocore_net", "accepted a new socket: %d", fd);
NET_SUM_GLOBAL_DYN_STAT(net_tcp_accept_stat, 1);
if (opt.send_bufsize > 0) {
@@ -440,6 +461,7 @@ NetAccept::acceptFastEvent(int event, void *ep)
}
// check return value from accept()
if (res < 0) {
+ Debug("iocore_net", "received : %s", strerror(errno));
res = -errno;
if (res == -EAGAIN || res == -ECONNABORTED
#if defined(linux)
@@ -458,9 +480,7 @@ NetAccept::acceptFastEvent(int event, void *ep)
}
vc = (UnixNetVConnection *)this->getNetProcessor()->allocate_vc(e->ethread);
- if (!vc) {
- goto Ldone;
- }
+ ink_release_assert(vc);
NET_SUM_GLOBAL_DYN_STAT(net_connections_currently_open_stat, 1);
vc->id = net_next_connection_number();
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index 11bf503..c8bc1e8 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -92,6 +92,7 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
ProxyMutex *mutex = this_ethread()->mutex.get();
int accept_threads = opt.accept_threads; // might be changed.
IpEndpoint accept_ip; // local binding address.
+ int listen_per_thread = 0;
NetAccept *na = createNetAccept(opt);
na->id = ink_atomic_increment(&net_accept_number, 1);
@@ -101,6 +102,10 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
if (opt.accept_threads < 0) {
REC_ReadConfigInteger(accept_threads, "proxy.config.accept_threads");
}
+ REC_ReadConfigInteger(listen_per_thread, "proxy.config.exec_thread.listen");
+ if (accept_threads > 0 && listen_per_thread > 0) {
+ Fatal("Please disable accept_threads or exec_threads.listen");
+ }
NET_INCREMENT_DYN_STAT(net_accepts_currently_open_stat);
@@ -137,7 +142,7 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions cons
na->action_->server = &na->server;
if (opt.frequent_accept) { // true
- if (accept_threads > 0) {
+ if (accept_threads > 0 && listen_per_thread == 0) {
na->init_accept_loop();
} else {
na->init_accept_per_thread();
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 62547c0..57883fb 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -116,6 +116,8 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.config.exec_thread.affinity", RECD_INT, "1", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-4]", RECA_READ_ONLY}
,
+ {RECT_CONFIG, "proxy.config.exec_thread.listen", RECD_INT, "0", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-1]", RECA_READ_ONLY}
+ ,
{RECT_CONFIG, "proxy.config.accept_threads", RECD_INT, "1", RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-" TS_STR(TS_MAX_NUMBER_EVENT_THREADS) "]", RECA_READ_ONLY}
,
{RECT_CONFIG, "proxy.config.task_threads", RECD_INT, "2", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-" TS_STR(TS_MAX_NUMBER_EVENT_THREADS) "]", RECA_READ_ONLY}
diff --git a/src/traffic_manager/traffic_manager.cc b/src/traffic_manager/traffic_manager.cc
index e6f7192..e6f14e6 100644
--- a/src/traffic_manager/traffic_manager.cc
+++ b/src/traffic_manager/traffic_manager.cc
@@ -557,6 +557,11 @@ main(int argc, const char **argv)
}
RecGetRecordInt("proxy.config.net.connections_throttle", &fds_throttle);
+ RecInt listen_per_thread = 0;
+ RecGetRecordInt("proxy.config.exec_thread.listen", &listen_per_thread);
+ if (listen_per_thread > 0) { // Turn off listening. Traffic server is going to listen on all the threads.
+ listen_off = true;
+ }
set_process_limits(fds_throttle); // as root
[trafficserver] 02/02: Fix the malformed threads table
Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 7bd0a535a58c90e7bc463987becfab9ed8db6f83
Author: Vijay Mamidi <vi...@yahoo.com>
AuthorDate: Sat Oct 26 15:05:26 2019 -0700
Fix the malformed threads table
(cherry picked from commit 14b33b54dbc88d49f58fb41f9ad06bde1c36c964)
---
doc/admin-guide/files/records.config.en.rst | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst
index f875519..d52c0af 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -327,15 +327,15 @@ Thread Variables
The number of accept threads. If disabled (``0``), then accepts will be done
in each of the worker threads.
- ============== ================== ===================
- accept_threads exec_thread.listen Effect
- ============== ================== ===================
- ``0`` ``0`` All worker threads accept new connections and share listen fd.
- ``1`` ``0`` New conections are accepted on a dedicated accept thread and distributed to worker threads in round robin fashion.
- ``0`` ``1`` All worker threads listen on the same port using SO_REUSEPORT.
- Each thread has its own listen and new connections are accepted on all the threads.
-
- By default, `proxy.config.accept_threads` is set to 1 and `proxy.config.exec_thread.listen` is set to 0.
+ ==================== ====================== =====================
+ accept_threads exec_thread.listen Effect
+ ==================== ====================== =====================
+ ``0`` ``0`` All worker threads accept new connections and share listen fd.
+ ``1`` ``0`` New conections are accepted on a dedicated accept thread and distributed to worker threads in round robin fashion.
+ ``0`` ``1`` All worker threads listen on the same port using SO_REUSEPORT. Each thread has its own listen fd and new connections are accepted on all the threads.
+ ==================== ====================== =====================
+
+ By default, `proxy.config.accept_threads` is set to 1 and `proxy.config.exec_thread.listen` is set to 0.
.. ts:cv:: CONFIG proxy.config.thread.default.stacksize INT 1048576
Default thread stack size, in bytes, for all threads (default is 1 MB).