You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/05/10 19:44:49 UTC

svn commit: r1336813 - /tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Author: markt
Date: Thu May 10 17:44:49 2012
New Revision: 1336813

URL: http://svn.apache.org/viewvc?rev=1336813&view=rev
Log:
Fix a problem whereby if the poller was under low but consistent load (>1 request/per second and always less than 1s between requests) timeouts never took place.
After the change, timeouts will be processed every X seconds where pollerTimeout <= X <= (timoutInterval + pollerTimeout + time taken to process timeouts)
Note the default values for pollerTimeout and timeoutInterval are 1000ms

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

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?rev=1336813&r1=1336812&r2=1336813&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu May 10 17:44:49 2012
@@ -1376,13 +1376,16 @@ public class NioEndpoint extends Abstrac
 
         protected void timeout(int keyCount, boolean hasEvents) {
             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 ( ((keyCount>0 || hasEvents) ||(now < nextExpiration)) && (!close) ) {
+            // This method is called on every loop of the Poller. Don't process
+            // timeouts on every loop of the Poller since that would create too
+            // much load and timeouts can afford to wait a few seconds.
+            // However, do process timeouts if any of the following are true:
+            // - the selector simply timed out (suggests there isn't much load)
+            // - the nextExpiration time has passed
+            // - the server socket is being closed
+            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;
@@ -1414,9 +1417,6 @@ public class NioEndpoint extends Abstrac
                             key.interestOps(0);
                             ka.interestOps(0); //avoid duplicate timeout calls
                             cancelledKey(key, SocketStatus.TIMEOUT);
-                        } else if (timeout > -1) {
-                            long nextTime = now+(timeout-delta);
-                            nextExpiration = (nextTime < nextExpiration)?nextTime:nextExpiration;
                         }
                     } else if (ka.isAsync() || ka.getComet()) {
                         // Async requests with a timeout of 0 or less never timeout
@@ -1435,8 +1435,15 @@ public class NioEndpoint extends Abstrac
                     cancelledKey(key, SocketStatus.ERROR);
                 }
             }//for
-            if ( log.isTraceEnabled() ) log.trace("timeout completed: keys processed="+keycount+"; now="+now+"; nextExpiration="+prevExp+"; "+
-                                                  "keyCount="+keyCount+"; hasEvents="+hasEvents +"; eval="+( (now < prevExp) && (keyCount>0 || hasEvents) && (!close) ));
+            long prevExp = nextExpiration; //for logging purposes only
+            nextExpiration = System.currentTimeMillis() +
+                    socketProperties.getTimeoutInterval();
+            if (log.isTraceEnabled()) {
+                log.trace("timeout completed: keys processed=" + keycount +
+                        "; now=" + now + "; nextExpiration=" + prevExp +
+                        "; keyCount=" + keyCount + "; hasEvents=" + hasEvents +
+                        "; eval=" + ((now < prevExp) && (keyCount>0 || hasEvents) && (!close) ));
+            }
 
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org