From a656f500694934b6d65c48d21d1a68a0b68e6dec Mon Sep 17 00:00:00 2001 From: fhanik Date: Mon, 6 Aug 2007 23:19:17 +0000 Subject: [PATCH] Improve upon poller timeout handling, to not waste cycles running the timeout setting too often same fix as 6.0.x git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@563330 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/coyote/http11/Http11NioProtocol.java | 2 +- java/org/apache/tomcat/util/net/NioEndpoint.java | 11 ++++++++--- java/org/apache/tomcat/util/net/SocketProperties.java | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java index dcd5f4e0f..3e658ca66 100644 --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ b/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -710,7 +710,7 @@ public class Http11NioProtocol implements ProtocolHandler, MBeanRegistration // Associate the connection with the processor. The next request // processed by this thread will use either a new or a recycled // processor. - if (log.isDebugEnabled()) log.debug("Not recycling ["+processor+"] Comet="+((NioEndpoint.KeyAttachment)socket.getAttachment(false)).getComet()); + //if (log.isDebugEnabled()) log.debug("Not recycling ["+processor+"] Comet="+((NioEndpoint.KeyAttachment)socket.getAttachment(false)).getComet()); connections.put(socket, processor); if (processor.comet) { NioEndpoint.KeyAttachment att = (NioEndpoint.KeyAttachment)socket.getAttachment(false); diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index b246c5377..73bbc2869 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1574,8 +1574,11 @@ public class NioEndpoint { long now = System.currentTimeMillis(); //don't process timeouts too frequently, but if the selector simply timed out //then we can check timeouts to avoid gaps - if ( (now < nextExpiration) && (keyCount>0 || hasEvents) && (!close) ) return; - nextExpiration = now + (long)socketProperties.getSoTimeout(); + if ( ((keyCount>0 || hasEvents) ||(now < nextExpiration)) && (!close) ) { + return; + } + long prevExp = nextExpiration; //for logging purposes only + nextExpiration = now + socketProperties.getTimeoutInterval(); //timeout Set keys = selector.keys(); int keycount = 0; @@ -1613,7 +1616,9 @@ public class NioEndpoint { cancelledKey(key, SocketStatus.ERROR,false); } }//for - if ( log.isDebugEnabled() ) log.debug("Poller processed "+keycount+" keys through timeout"); + if ( log.isDebugEnabled() ) log.debug("timeout completed: keys processed="+keycount+"; now="+now+"; nextExpiration="+prevExp+"; "+ + "keyCount="+keyCount+"; hasEvents="+hasEvents +"; eval="+( (now < prevExp) && (keyCount>0 || hasEvents) && (!close) )); + } } diff --git a/java/org/apache/tomcat/util/net/SocketProperties.java b/java/org/apache/tomcat/util/net/SocketProperties.java index 7a50135ed..b66dd515e 100644 --- a/java/org/apache/tomcat/util/net/SocketProperties.java +++ b/java/org/apache/tomcat/util/net/SocketProperties.java @@ -156,6 +156,13 @@ public class SocketProperties { * Default value is 1 */ protected int performanceBandwidth = 1; + + /** + * Minimum time to pass by before another socket expiration run performs + * This avoids unncessary loops over all sockets when the poller is busy + */ + protected long timeoutInterval = 1000; + private Socket properties; public void setProperties(Socket socket) throws SocketException{ @@ -351,4 +358,12 @@ public class SocketProperties { this.bufferPool = directBufferPool; } + public void setTimeoutInterval(long toi){ + this.timeoutInterval = toi; + } + + public long getTimeoutInterval(){ + return timeoutInterval; + } + } \ No newline at end of file -- 2.11.0