Improve upon poller timeout handling, to not waste cycles running the timeout setting...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 6 Aug 2007 23:19:17 +0000 (23:19 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 6 Aug 2007 23:19:17 +0000 (23:19 +0000)
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
java/org/apache/tomcat/util/net/NioEndpoint.java
java/org/apache/tomcat/util/net/SocketProperties.java

index dcd5f4e..3e658ca 100644 (file)
@@ -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);
index b246c53..73bbc28 100644 (file)
@@ -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<SelectionKey> 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) ));
+
         }
     }
 
index 7a50135..b66dd51 100644 (file)
@@ -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