Author: markt Date: Thu May 10 17:46:45 2012 New Revision: 1336814 URL: http://svn.apache.org/viewvc?rev=1336814&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/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1336813 Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1336814&r1=1336813&r2=1336814&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu May 10 17:46:45 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,true); - } 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,false); } }//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) )); + } } } Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1336814&r1=1336813&r2=1336814&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu May 10 17:46:45 2012 @@ -113,6 +113,12 @@ <code>InputFilter</code>s are recycled between requests. (markt) </fix> <fix> + <bug>53061</bug>: Fix a problem in the NIO connector whereby if the + poller was under low but consistent load (>1 request/per second and + always less than 1 second between requests) timeouts never took place. + (markt) + </fix> + <fix> <bug>53173</bug> (<rev>1333116</rev>) : Properly count down maxConnections (fhanik) </fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org