Author: fhanik Date: Mon Aug 6 16:19:17 2007 New Revision: 563330 URL: http://svn.apache.org/viewvc?view=rev&rev=563330 Log: Improve upon poller timeout handling, to not waste cycles running the timeout setting too often same fix as 6.0.x
Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/SocketProperties.java Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?view=diff&rev=563330&r1=563329&r2=563330 ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Mon Aug 6 16:19:17 2007 @@ -710,7 +710,7 @@ // 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); Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=563330&r1=563329&r2=563330 ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Aug 6 16:19:17 2007 @@ -1574,8 +1574,11 @@ 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<SelectionKey> keys = selector.keys(); int keycount = 0; @@ -1613,7 +1616,9 @@ 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) )); + } } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketProperties.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketProperties.java?view=diff&rev=563330&r1=563329&r2=563330 ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SocketProperties.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketProperties.java Mon Aug 6 16:19:17 2007 @@ -156,6 +156,13 @@ * 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{ @@ -349,6 +356,14 @@ public void setDirectBufferPool(int directBufferPool) { this.bufferPool = directBufferPool; + } + + public void setTimeoutInterval(long toi){ + this.timeoutInterval = toi; + } + + public long getTimeoutInterval(){ + return timeoutInterval; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]