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

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new ead24df  Force the use of a single acceptor thread
ead24df is described below

commit ead24df9f54def700c1e6335212c85dc434e3fd1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 22 10:45:38 2021 +0000

    Force the use of a single acceptor thread
    
    9.0.x onwards uses a single acceptor thread.
    Multiple acceptor threads offered little/no performance benefit.
    Using a single acceptor thread allows bbbb7a8c (detect and protect
    against a known OS bug) to be back-ported
---
 java/org/apache/coyote/AbstractProtocol.java       | 18 +++++++
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 57 ++++++++++++++++------
 java/org/apache/tomcat/util/net/AprEndpoint.java   | 10 ++--
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  6 ---
 java/org/apache/tomcat/util/net/NioEndpoint.java   |  5 --
 .../apache/tomcat/util/net/mbeans-descriptors.xml  |  9 ++--
 webapps/docs/changelog.xml                         |  3 ++
 webapps/docs/config/ajp.xml                        | 10 +---
 webapps/docs/config/http.xml                       | 10 +---
 9 files changed, 73 insertions(+), 55 deletions(-)

diff --git a/java/org/apache/coyote/AbstractProtocol.java 
b/java/org/apache/coyote/AbstractProtocol.java
index 002b0c0..43f465a 100644
--- a/java/org/apache/coyote/AbstractProtocol.java
+++ b/java/org/apache/coyote/AbstractProtocol.java
@@ -337,9 +337,27 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler,
         return endpoint.getConnectionCount();
     }
 
+    /**
+     * Unused.
+     *
+     * @param threadCount   Ignored
+     *
+     * @deprecated  This attribute is hard-coded to {@code 1} and is no longer
+     *              configurable.
+     */
+    @Deprecated
     public void setAcceptorThreadCount(int threadCount) {
         endpoint.setAcceptorThreadCount(threadCount);
     }
+    /**
+     * Unused.
+     *
+     * @return  Always returns {@code 1}
+     *
+     * @deprecated  This attribute is hard-coded to {@code 1} and is no longer
+     *              configurable.
+     */
+    @Deprecated
     public int getAcceptorThreadCount() {
       return endpoint.getAcceptorThreadCount();
     }
diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 8830658..072e5b6 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -191,7 +191,8 @@ public abstract class AbstractEndpoint<S> {
     }
 
     /**
-     * Threads used to accept new connections and pass them to worker threads.
+     * Thread used to accept new connections and pass them to worker threads.
+     * This is hard-coded to use a single acceptor.
      */
     protected Acceptor[] acceptors;
 
@@ -445,14 +446,39 @@ public abstract class AbstractEndpoint<S> {
 
 
     /**
-     * Acceptor thread count.
+     * Unused.
+     *
+     * @deprecated  This attribute is hard-coded to {@code 1} and is no longer
+     *              configurable.
      */
+    @Deprecated
     protected int acceptorThreadCount = 1;
 
+    /**
+     * Unused.
+     *
+     * @param acceptorThreadCount   Ignored
+     *
+     * @deprecated  This attribute is hard-coded to {@code 1} and is no longer
+     *              configurable.
+     */
+    @Deprecated
     public void setAcceptorThreadCount(int acceptorThreadCount) {
-        this.acceptorThreadCount = acceptorThreadCount;
+        // NO-OP;
+    }
+
+    /**
+     * Unused.
+     *
+     * @return  Always returns {@code 1}
+     *
+     * @deprecated  This attribute is hard-coded to {@code 1} and is no longer
+     *              configurable.
+     */
+    @Deprecated
+    public int getAcceptorThreadCount() {
+        return 1;
     }
-    public int getAcceptorThreadCount() { return acceptorThreadCount; }
 
 
     /**
@@ -1014,6 +1040,8 @@ public abstract class AbstractEndpoint<S> {
                 }
             }
             // Wait for upto 1000ms acceptor threads to unlock
+            // Should only be one thread but retain this code in case the
+            // acceptor start has been customised.
             long waitLeft = 1000;
             for (Acceptor acceptor : acceptors) {
                 while (waitLeft > 0 &&
@@ -1238,18 +1266,15 @@ public abstract class AbstractEndpoint<S> {
     }
 
     protected final void startAcceptorThreads() {
-        int count = getAcceptorThreadCount();
-        acceptors = new Acceptor[count];
-
-        for (int i = 0; i < count; i++) {
-            acceptors[i] = createAcceptor();
-            String threadName = getName() + "-Acceptor-" + i;
-            acceptors[i].setThreadName(threadName);
-            Thread t = new Thread(acceptors[i], threadName);
-            t.setPriority(getAcceptorThreadPriority());
-            t.setDaemon(getDaemon());
-            t.start();
-        }
+        acceptors = new Acceptor[1];
+
+        acceptors[0] = createAcceptor();
+        String threadName = getName() + "-Acceptor-0";
+        acceptors[0].setThreadName(threadName);
+        Thread t = new Thread(acceptors[0], threadName);
+        t.setPriority(getAcceptorThreadPriority());
+        t.setDaemon(getDaemon());
+        t.start();
     }
 
 
diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 96542db..8556040 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -349,12 +349,6 @@ public class AprEndpoint extends AbstractEndpoint<Long> 
implements SNICallBack {
             setUseSendfileInternal(false);
         }
 
-        // Initialize thread count default for acceptor
-        if (acceptorThreadCount == 0) {
-            // FIXME: Doesn't seem to work that well with multiple accept 
threads
-            acceptorThreadCount = 1;
-        }
-
         // Delay accepting of new connections until data is available
         // Only Linux kernels 2.4 + have that implemented
         // on other platforms this call is noop and will return APR_ENOTIMPL.
@@ -496,7 +490,9 @@ public class AprEndpoint extends AbstractEndpoint<Long> 
implements SNICallBack {
             // Stop the Poller calling select
             poller.stop();
 
-            // Wait for the acceptor(s) to shutdown
+            // Wait for the acceptor to shutdown.
+            // Should only be one thread but retain this code in case the
+            // acceptor start has been customised.
             for (AbstractEndpoint.Acceptor acceptor : acceptors) {
                 long waitLeft = 10000;
                 while (waitLeft > 0 &&
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index a2e0bd3..84a8303 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -147,12 +147,6 @@ public class Nio2Endpoint extends 
AbstractJsseEndpoint<Nio2Channel> {
         InetSocketAddress addr = (getAddress()!=null?new 
InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
         serverSock.bind(addr, getAcceptCount());
 
-        // Initialize thread count defaults for acceptor, poller
-        if (acceptorThreadCount != 1) {
-            // NIO2 does not allow any form of IO concurrency
-            acceptorThreadCount = 1;
-        }
-
         // Initialize SSL if needed
         initialiseSsl();
     }
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java 
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 8f2ee6c..6826985 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -231,11 +231,6 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel> {
         }
         serverSock.configureBlocking(true); //mimic APR behavior
 
-        // Initialize thread count defaults for acceptor, poller
-        if (acceptorThreadCount == 0) {
-            // FIXME: Doesn't seem to work that well with multiple accept 
threads
-            acceptorThreadCount = 1;
-        }
         if (pollerThreadCount <= 0) {
             //minimum one poller thread
             pollerThreadCount = 1;
diff --git a/java/org/apache/tomcat/util/net/mbeans-descriptors.xml 
b/java/org/apache/tomcat/util/net/mbeans-descriptors.xml
index fbff758..62642dd 100644
--- a/java/org/apache/tomcat/util/net/mbeans-descriptors.xml
+++ b/java/org/apache/tomcat/util/net/mbeans-descriptors.xml
@@ -30,7 +30,8 @@
                  type="int"/>
 
     <attribute   name="acceptorThreadCount"
-                 type="int"/>
+                 type="int"
+                 description="Deprecated - do not use"/>
 
     <attribute   name="acceptorThreadPriority"
                  type="int"/>
@@ -253,7 +254,8 @@
                  type="int"/>
 
     <attribute   name="acceptorThreadCount"
-                 type="int"/>
+                 type="int"
+                 description="Deprecated - do not use"/>
 
     <attribute   name="acceptorThreadPriority"
                  type="int"/>
@@ -464,7 +466,8 @@
                  type="int"/>
 
     <attribute   name="acceptorThreadCount"
-                 type="int"/>
+                 type="int"
+                 description="Deprecated - do not use"/>
 
     <attribute   name="acceptorThreadPriority"
                  type="int"/>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e590f85..ea16c3a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -156,6 +156,9 @@
         Improve error handling if APR/Native fails to accept an incoming
         connection. (markt)
       </fix>
+      <add>
+        Hard code all connectors to use a single acceptor thread. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="WebSocket">
diff --git a/webapps/docs/config/ajp.xml b/webapps/docs/config/ajp.xml
index de88e29..75d0049 100644
--- a/webapps/docs/config/ajp.xml
+++ b/webapps/docs/config/ajp.xml
@@ -321,16 +321,8 @@
       value is 100.</p>
     </attribute>
 
-    <attribute name="acceptorThreadCount" required="false">
-      <p>The number of threads to be used to accept connections. Increase this
-      value on a multi CPU machine, although you would never really need more
-      than <code>2</code>. Also, with a lot of non keep alive connections, you
-      might want to increase this value as well. Default value is
-      <code>1</code>.</p>
-    </attribute>
-
     <attribute name="acceptorThreadPriority" required="false">
-      <p>The priority of the acceptor threads. The threads used to accept
+      <p>The priority of the acceptor thread. The thread used to accept
       new connections. The default value is <code>5</code> (the value of the
       <code>java.lang.Thread.NORM_PRIORITY</code> constant). See the JavaDoc
       for the <code>java.lang.Thread</code> class for more details on what
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index aa1da23..8017844 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -349,16 +349,8 @@
       value is 100.</p>
     </attribute>
 
-    <attribute name="acceptorThreadCount" required="false">
-      <p>The number of threads to be used to accept connections. Increase this
-      value on a multi CPU machine, although you would never really need more
-      than <code>2</code>. Also, with a lot of non keep alive connections, you
-      might want to increase this value as well. Default value is
-      <code>1</code>.</p>
-    </attribute>
-
     <attribute name="acceptorThreadPriority" required="false">
-      <p>The priority of the acceptor threads. The threads used to accept
+      <p>The priority of the acceptor thread. The thread used to accept
       new connections. The default value is <code>5</code> (the value of the
       <code>java.lang.Thread.NORM_PRIORITY</code> constant). See the JavaDoc
       for the <code>java.lang.Thread</code> class for more details on what

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to