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 6b3a521 Back-port removal of PollerThreadCount
6b3a521 is described below
commit 6b3a521ff8aa83034ea339f0355dfbef33ce157a
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Feb 17 17:40:57 2022 +0000
Back-port removal of PollerThreadCount
Part of aligning 8.5.x with 9.0.x onwards.
---
.../apache/coyote/http11/Http11NioProtocol.java | 19 +++-
java/org/apache/tomcat/util/net/NioEndpoint.java | 109 +++++++++++----------
webapps/docs/changelog.xml | 4 +
webapps/docs/config/http.xml | 17 +---
4 files changed, 80 insertions(+), 69 deletions(-)
diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java
b/java/org/apache/coyote/http11/Http11NioProtocol.java
index f872ffe..dfc9720 100644
--- a/java/org/apache/coyote/http11/Http11NioProtocol.java
+++ b/java/org/apache/coyote/http11/Http11NioProtocol.java
@@ -46,12 +46,27 @@ public class Http11NioProtocol extends
AbstractHttp11JsseProtocol<NioChannel> {
// -------------------- Pool setup --------------------
+ /**
+ * NO-OP.
+ *
+ * @param count Unused
+ *
+ * @deprecated This setter will be removed in Tomcat 10.
+ */
+ @Deprecated
public void setPollerThreadCount(int count) {
- ((NioEndpoint)getEndpoint()).setPollerThreadCount(count);
}
+ /**
+ * Always returns 1.
+ *
+ * @return 1
+ *
+ * @deprecated This getter will be removed in Tomcat 10.
+ */
+ @Deprecated
public int getPollerThreadCount() {
- return ((NioEndpoint)getEndpoint()).getPollerThreadCount();
+ return 1;
}
public void setSelectorTimeout(long timeout) {
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 7249534..1d1e34c 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -41,7 +41,6 @@ import java.util.Iterator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import javax.net.ssl.SSLEngine;
@@ -145,11 +144,23 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
/**
- * Poller thread count.
+ * NO-OP.
+ *
+ * @param pollerThreadCount Unused
+ *
+ * @deprecated Will be removed in Tomcat 10.
+ */
+ @Deprecated
+ public void setPollerThreadCount(int pollerThreadCount) { }
+ /**
+ * Always returns 1.
+ *
+ * @return Always 1.
+ *
+ * @deprecated Will be removed in Tomcat 10.
*/
- private int pollerThreadCount =
Math.min(2,Runtime.getRuntime().availableProcessors());
- public void setPollerThreadCount(int pollerThreadCount) {
this.pollerThreadCount = pollerThreadCount; }
- public int getPollerThreadCount() { return pollerThreadCount; }
+ @Deprecated
+ public int getPollerThreadCount() { return 1; }
private long selectorTimeout = 1000;
public void setSelectorTimeout(long timeout) { this.selectorTimeout =
timeout;}
@@ -158,16 +169,17 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
/**
* The socket poller.
*/
- private Poller[] pollers = null;
- private AtomicInteger pollerRotater = new AtomicInteger(0);
+ private Poller poller = null;
/**
- * Return an available poller in true round robin fashion.
+ * Not used.
+ *
+ * @return The poller
*
- * @return The next poller in sequence
+ * @deprecated Will be removed in Tomcat 9.
*/
+ @Deprecated
public Poller getPoller0() {
- int idx = Math.abs(pollerRotater.incrementAndGet()) % pollers.length;
- return pollers[idx];
+ return poller;
}
@@ -198,14 +210,10 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
* for the next request to be received on the socket
*/
public int getKeepAliveCount() {
- if (pollers == null) {
+ if (poller == null) {
return 0;
} else {
- int sum = 0;
- for (int i=0; i<pollers.length; i++) {
- sum += pollers[i].getKeyCount();
- }
- return sum;
+ return poller.getKeyCount();
}
}
@@ -217,13 +225,20 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
*/
@Override
public void bind() throws Exception {
+ initServerSocket();
- if (!getUseInheritedChannel()) {
- serverSock = ServerSocketChannel.open();
- socketProperties.setProperties(serverSock.socket());
- InetSocketAddress addr = (getAddress()!=null?new
InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
- serverSock.socket().bind(addr,getAcceptCount());
- } else {
+ setStopLatch(new CountDownLatch(1));
+
+ // Initialize SSL if needed
+ initialiseSsl();
+
+ selectorPool.open();
+ }
+
+ // Separated out to make it easier for folks that extend NioEndpoint to
+ // implement custom [server]sockets
+ protected void initServerSocket() throws Exception {
+ if (getUseInheritedChannel()) {
// Retrieve the channel provided by the OS
Channel ic = System.inheritedChannel();
if (ic instanceof ServerSocketChannel) {
@@ -232,19 +247,13 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
if (serverSock == null) {
throw new
IllegalArgumentException(sm.getString("endpoint.init.bind.inherited"));
}
+ } else {
+ serverSock = ServerSocketChannel.open();
+ socketProperties.setProperties(serverSock.socket());
+ InetSocketAddress addr = (getAddress()!=null?new
InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
+ serverSock.socket().bind(addr,getAcceptCount());
}
serverSock.configureBlocking(true); //mimic APR behavior
-
- if (pollerThreadCount <= 0) {
- //minimum one poller thread
- pollerThreadCount = 1;
- }
- setStopLatch(new CountDownLatch(pollerThreadCount));
-
- // Initialize SSL if needed
- initialiseSsl();
-
- selectorPool.open();
}
@@ -272,15 +281,12 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
initializeConnectionLatch();
- // Start poller threads
- pollers = new Poller[getPollerThreadCount()];
- for (int i=0; i<pollers.length; i++) {
- pollers[i] = new Poller();
- Thread pollerThread = new Thread(pollers[i], getName() +
"-ClientPoller-"+i);
- pollerThread.setPriority(threadPriority);
- pollerThread.setDaemon(true);
- pollerThread.start();
- }
+ // Start poller thread
+ poller = new Poller();
+ Thread pollerThread = new Thread(poller, getName() + "-Poller");
+ pollerThread.setPriority(threadPriority);
+ pollerThread.setDaemon(true);
+ pollerThread.start();
startAcceptorThreads();
}
@@ -299,12 +305,9 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
if (running) {
running = false;
unlockAccept();
- for (int i=0; pollers!=null && i<pollers.length; i++) {
- if (pollers[i]==null) {
- continue;
- }
- pollers[i].destroy();
- pollers[i] = null;
+ if (poller != null) {
+ poller.destroy();
+ poller = null;
}
try {
if (!getStopLatch().await(selectorTimeout + 100,
TimeUnit.MILLISECONDS)) {
@@ -425,7 +428,8 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
channel.setIOChannel(socket);
channel.reset();
}
- getPoller0().register(channel);
+ poller.register(channel);
+ return true;
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
try {
@@ -433,10 +437,9 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
} catch (Throwable tt) {
ExceptionUtils.handleThrowable(tt);
}
- // Tell to close the socket
- return false;
}
- return true;
+ // Tell to close the socket if needed
+ return false;
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1beb4c0..e573352 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -174,6 +174,10 @@
HTTP headers tracks this change. Pull request provided by zhenguoli.
(markt)
</fix>
+ <update>
+ Remove <code>pollerThreadCount</code> Connector attribute for NIO.
+ One poller thread is sufficient. (remm/markt)
+ </update>
</changelog>
</subsection>
<subsection name="Jasper">
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index b9fccbf..b984e79 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -795,18 +795,6 @@
<attributes>
- <attribute name="pollerThreadCount" required="false">
- <p>(int)The number of threads to be used to run for the polling events.
- Default value is <code>1</code> per processor but not more than 2.<br/>
- When accepting a socket, the operating system holds a global lock. So
the benefit of
- going above 2 threads diminishes rapidly. Having more than one thread
is for
- system that need to accept connections very rapidly. However usually
just
- increasing <code>acceptCount</code> will solve that problem.
- Increasing this value may also be beneficial when a large amount of
send file
- operations are going on.
- </p>
- </attribute>
-
<attribute name="pollerThreadPriority" required="false">
<p>(int)The priority of the poller threads.
The default value is <code>5</code> (the value of the
@@ -1601,8 +1589,9 @@
<subsection name="SSL Support - Connector - NIO and NIO2">
- <p>When APR/native is enabled, the connectors will default to using OpenSSL
through JSSE,
- which may be more optimized than the JSSE Java implementation depending on
the processor being used,
+ <p>When APR/native is enabled, the connectors will default to using
+ OpenSSL through JSSE, which may be more optimized than the JSSE Java
+ implementation depending on the processor being used,
and can be complemented with many commercial accelerator components.</p>
<p>The following NIO and NIO2 SSL configuration attributes are not specific
to
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]