This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 2045d61 Avoid using object caches when disabled
2045d61 is described below
commit 2045d619a317af1cef2774402839e2ba15ef40cb
Author: remm <[email protected]>
AuthorDate: Wed Apr 17 11:08:48 2019 +0200
Avoid using object caches when disabled
The special size value 0 allows disabling them, as is documented. In
addition to the structure creation, using a SynchronizedStack when they
have zero size still causes connector wide synchronization.
---
.../apache/tomcat/util/net/AbstractEndpoint.java | 5 +-
java/org/apache/tomcat/util/net/AprEndpoint.java | 13 +++--
java/org/apache/tomcat/util/net/Nio2Endpoint.java | 35 +++++++++-----
java/org/apache/tomcat/util/net/NioEndpoint.java | 56 +++++++++++++++-------
webapps/docs/changelog.xml | 3 ++
5 files changed, 80 insertions(+), 32 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 64be45b..8d01292 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1066,7 +1066,10 @@ public abstract class AbstractEndpoint<S,U> {
if (socketWrapper == null) {
return false;
}
- SocketProcessorBase<S> sc = processorCache.pop();
+ SocketProcessorBase<S> sc = null;
+ if (processorCache != null) {
+ sc = processorCache.pop();
+ }
if (sc == null) {
sc = createSocketProcessor(socketWrapper, event);
} else {
diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index bfb5c55..fea7c15 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -455,8 +455,10 @@ public class AprEndpoint extends
AbstractEndpoint<Long,Long> implements SNICallB
running = true;
paused = false;
- processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getProcessorCache());
+ if (socketProperties.getProcessorCache() != 0) {
+ processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getProcessorCache());
+ }
// Create worker collection
if (getExecutor() == null) {
@@ -539,7 +541,10 @@ public class AprEndpoint extends
AbstractEndpoint<Long,Long> implements SNICallB
}
sendfile = null;
}
- processorCache.clear();
+ if (processorCache != null) {
+ processorCache.clear();
+ processorCache = null;
+ }
}
shutdownExecutor();
}
@@ -2119,7 +2124,7 @@ public class AprEndpoint extends
AbstractEndpoint<Long,Long> implements SNICallB
socketWrapper = null;
event = null;
//return to cache
- if (running && !paused) {
+ if (running && !paused && processorCache != null) {
processorCache.push(this);
}
}
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 65cdf4b..6d3e5d0 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -163,13 +163,17 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
running = true;
paused = false;
- processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getProcessorCache());
- nioChannels = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getBufferPool());
+ if (socketProperties.getProcessorCache() != 0) {
+ processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getProcessorCache());
+ }
+ if (socketProperties.getBufferPool() != 0) {
+ nioChannels = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getBufferPool());
+ }
// Create worker collection
- if ( getExecutor() == null ) {
+ if (getExecutor() == null) {
createExecutor();
}
@@ -229,8 +233,14 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
}
}
});
- nioChannels.clear();
- processorCache.clear();
+ if (nioChannels != null) {
+ nioChannels.clear();
+ nioChannels = null;
+ }
+ if (processorCache != null) {
+ processorCache.clear();
+ processorCache = null;
+ }
}
}
@@ -305,7 +315,10 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
protected boolean setSocketOptions(AsynchronousSocketChannel socket) {
try {
socketProperties.setProperties(socket);
- Nio2Channel channel = nioChannels.pop();
+ Nio2Channel channel = null;
+ if (nioChannels != null) {
+ channel = nioChannels.pop();
+ }
if (channel == null) {
SocketBufferHandler bufhandler = new SocketBufferHandler(
socketProperties.getAppReadBufSize(),
@@ -1785,7 +1798,7 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
// Close socket and pool
socketWrapper.close();
if (running && !paused) {
- if (!nioChannels.push(socketWrapper.getSocket())) {
+ if (nioChannels == null ||
!nioChannels.push(socketWrapper.getSocket())) {
socketWrapper.getSocket().free();
}
}
@@ -1795,7 +1808,7 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
} else if (handshake == -1 ) {
socketWrapper.close();
if (running && !paused) {
- if (!nioChannels.push(socketWrapper.getSocket())) {
+ if (nioChannels == null ||
!nioChannels.push(socketWrapper.getSocket())) {
socketWrapper.getSocket().free();
}
}
@@ -1821,7 +1834,7 @@ public class Nio2Endpoint extends
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
socketWrapper = null;
event = null;
//return to cache
- if (running && !paused) {
+ if (running && !paused && processorCache != null) {
processorCache.push(this);
}
}
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 0516ee9..2e3646a 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -262,15 +262,21 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
running = true;
paused = false;
- processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getProcessorCache());
- eventCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getEventCache());
- nioChannels = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
- socketProperties.getBufferPool());
+ if (socketProperties.getProcessorCache() != 0) {
+ processorCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getProcessorCache());
+ }
+ if (socketProperties.getEventCache() != 0) {
+ eventCache = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getEventCache());
+ }
+ if (socketProperties.getBufferPool() != 0) {
+ nioChannels = new
SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE,
+ socketProperties.getBufferPool());
+ }
// Create worker collection
- if ( getExecutor() == null ) {
+ if (getExecutor() == null) {
createExecutor();
}
@@ -314,9 +320,18 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
log.warn(sm.getString("endpoint.nio.stopLatchAwaitInterrupted"), e);
}
shutdownExecutor();
- eventCache.clear();
- nioChannels.clear();
- processorCache.clear();
+ if (eventCache != null) {
+ eventCache.clear();
+ eventCache = null;
+ }
+ if (nioChannels != null) {
+ nioChannels.clear();
+ nioChannels = null;
+ }
+ if (processorCache != null) {
+ processorCache.clear();
+ processorCache = null;
+ }
}
}
@@ -390,7 +405,10 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
Socket sock = socket.socket();
socketProperties.setProperties(sock);
- NioChannel channel = nioChannels.pop();
+ NioChannel channel = null;
+ if (nioChannels != null) {
+ channel = nioChannels.pop();
+ }
if (channel == null) {
SocketBufferHandler bufhandler = new SocketBufferHandler(
socketProperties.getAppReadBufSize(),
@@ -478,7 +496,7 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
log.debug("Socket: [" + socket + "] closed");
}
if (running && !paused) {
- if (!nioChannels.push(socket)) {
+ if (nioChannels == null || !nioChannels.push(socket)) {
socket.free();
}
}
@@ -615,7 +633,10 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
* the Poller
*/
public void add(final NioChannel socket, final int interestOps) {
- PollerEvent r = eventCache.pop();
+ PollerEvent r = null;
+ if (eventCache != null) {
+ r = eventCache.pop();
+ }
if (r == null) {
r = new PollerEvent(socket, null, interestOps);
} else {
@@ -643,7 +664,7 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
try {
pe.run();
pe.reset();
- if (running && !paused) {
+ if (running && !paused && eventCache != null) {
eventCache.push(pe);
}
} catch ( Throwable x ) {
@@ -668,8 +689,11 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
socketWrapper.setWriteTimeout(getConnectionTimeout());
socketWrapper.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
socketWrapper.setSecure(isSSLEnabled());
- PollerEvent r = eventCache.pop();
socketWrapper.interestOps(SelectionKey.OP_READ);//this is what
OP_REGISTER turns into.
+ PollerEvent r = null;
+ if (eventCache != null) {
+ r = eventCache.pop();
+ }
if (r == null) {
r = new PollerEvent(socket, socketWrapper, OP_REGISTER);
} else {
@@ -1809,7 +1833,7 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
socketWrapper = null;
event = null;
//return to cache
- if (running && !paused) {
+ if (running && !paused && processorCache != null) {
processorCache.push(this);
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 45ab3a8..9e99e0b 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -70,6 +70,9 @@
<fix>
Implement poller timeout when using async IO with NIO. (remm)
</fix>
+ <fix>
+ Avoid creating and using object caches when they are disabled. (remm)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]