Author: markt Date: Wed Apr 6 20:13:31 2016 New Revision: 1738044 URL: http://svn.apache.org/viewvc?rev=1738044&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=59269 Correct the implementation of PersistentManagerBase so that minIdleSwap functions as designed and sessions are swapped out to keep the active session count below maxActiveSessions
Added: tomcat/tc8.5.x/trunk/test/org/apache/catalina/session/TestPersistentManager.java - copied, changed from r1738039, tomcat/trunk/test/org/apache/catalina/session/TestPersistentManager.java Modified: tomcat/tc8.5.x/trunk/ (props changed) tomcat/tc8.5.x/trunk/java/org/apache/catalina/session/PersistentManagerBase.java tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml tomcat/tc8.5.x/trunk/webapps/docs/config/manager.xml Propchange: tomcat/tc8.5.x/trunk/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Apr 6 20:13:31 2016 @@ -1 +1 @@ -/tomcat/trunk:1734785,1734799,1734845,1734928,1735041,1735044,1735480,1735577,1735597,1735599-1735600,1735615,1736145,1736162,1736209,1736280,1736297,1736299,1736489,1736646,1736703,1736836,1736849,1737104-1737105,1737112,1737117,1737119-1737120,1737155,1737157,1737192,1737280,1737339,1737632,1737664,1737715,1737748,1737785,1737834,1737860,1737959,1738005,1738007,1738014-1738015,1738018,1738022 +/tomcat/trunk:1734785,1734799,1734845,1734928,1735041,1735044,1735480,1735577,1735597,1735599-1735600,1735615,1736145,1736162,1736209,1736280,1736297,1736299,1736489,1736646,1736703,1736836,1736849,1737104-1737105,1737112,1737117,1737119-1737120,1737155,1737157,1737192,1737280,1737339,1737632,1737664,1737715,1737748,1737785,1737834,1737860,1737959,1738005,1738007,1738014-1738015,1738018,1738022,1738039,1738043 Modified: tomcat/tc8.5.x/trunk/java/org/apache/catalina/session/PersistentManagerBase.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/session/PersistentManagerBase.java?rev=1738044&r1=1738043&r2=1738044&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/java/org/apache/catalina/session/PersistentManagerBase.java (original) +++ tomcat/tc8.5.x/trunk/java/org/apache/catalina/session/PersistentManagerBase.java Wed Apr 6 20:13:31 2016 @@ -162,16 +162,18 @@ public abstract class PersistentManagerB /** - * Minimum time a session must be idle before it is swapped to disk. - * This overrides maxActiveSessions, to prevent thrashing if there are lots - * of active sessions. Setting to {@code -1} means it's ignored. + * The minimum time in seconds a session must be idle before it is eligible + * to be swapped to disk to keep the active session count below + * maxActiveSessions. Setting to {@code -1} means sessions will not be + * swapped out to keep the active session count down. */ protected int minIdleSwap = -1; + /** - * The maximum time a session may be idle before it should be swapped - * to file just on general principle. Setting this to {@code -1} means sessions - * should not be forced out. + * The maximum time in seconds a session may be idle before it is eligible + * to be swapped to disk due to inactivity. Setting this to {@code -1} means + * sessions should not be swapped out just because of inactivity. */ protected int maxIdleSwap = -1; @@ -233,19 +235,20 @@ public abstract class PersistentManagerB /** - * @return The time in seconds after which a session should be swapped out of - * memory to disk. + * @return The maximum time in seconds a session may be idle before it is + * eligible to be swapped to disk due to inactivity. A value of {@code -1} + * means sessions should not be swapped out just because of inactivity. */ public int getMaxIdleSwap() { - return maxIdleSwap; - } /** - * Sets the time in seconds after which a session should be swapped out of - * memory to disk. + * Sets the maximum time in seconds a session may be idle before it is + * eligible to be swapped to disk due to inactivity. Setting this to + * {@code -1} means sessions should not be swapped out just because of + * inactivity. * * @param max time in seconds to wait for possible swap out */ @@ -258,26 +261,25 @@ public abstract class PersistentManagerB support.firePropertyChange("maxIdleSwap", Integer.valueOf(oldMaxIdleSwap), Integer.valueOf(this.maxIdleSwap)); - } /** - * @return The minimum time in seconds that a session must be idle before - * it can be swapped out of memory, or {@code -1} if it can be swapped out - * at any time. + * @return The minimum time in seconds a session must be idle before it is + * eligible to be swapped to disk to keep the active session count below + * maxActiveSessions. A value of {@code -1} means sessions will not be + * swapped out to keep the active session count down. */ public int getMinIdleSwap() { - return minIdleSwap; - } /** - * Sets the minimum time in seconds that a session must be idle before - * it can be swapped out of memory due to maxActiveSession. Set it to {@code -1} - * if it can be swapped out at any time. + * Sets the minimum time in seconds a session must be idle before it is + * eligible to be swapped to disk to keep the active session count below + * maxActiveSessions. Setting to {@code -1} means sessions will not be + * swapped out to keep the active session count down. * * @param min time in seconds before a possible swap out */ @@ -941,7 +943,9 @@ public abstract class PersistentManagerB Session sessions[] = findSessions(); // FIXME: Smarter algorithm (LRU) - if (getMaxActiveSessions() >= sessions.length) + int limit = (int) (getMaxActiveSessions() * 0.9); + + if (limit >= sessions.length) return; if(log.isDebugEnabled()) @@ -949,7 +953,7 @@ public abstract class PersistentManagerB ("persistentManager.tooManyActive", Integer.valueOf(sessions.length))); - int toswap = sessions.length - getMaxActiveSessions(); + int toswap = sessions.length - limit; for (int i = 0; i < sessions.length && toswap > 0; i++) { StandardSession session = (StandardSession) sessions[i]; Copied: tomcat/tc8.5.x/trunk/test/org/apache/catalina/session/TestPersistentManager.java (from r1738039, tomcat/trunk/test/org/apache/catalina/session/TestPersistentManager.java) URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/test/org/apache/catalina/session/TestPersistentManager.java?p2=tomcat/tc8.5.x/trunk/test/org/apache/catalina/session/TestPersistentManager.java&p1=tomcat/trunk/test/org/apache/catalina/session/TestPersistentManager.java&r1=1738039&r2=1738044&rev=1738044&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/session/TestPersistentManager.java (original) +++ tomcat/tc8.5.x/trunk/test/org/apache/catalina/session/TestPersistentManager.java Wed Apr 6 20:13:31 2016 @@ -16,12 +16,13 @@ */ package org.apache.catalina.session; +import org.junit.Assert; +import org.junit.Test; + import org.apache.catalina.Context; import org.apache.catalina.Host; import org.apache.tomcat.unittest.TesterContext; import org.apache.tomcat.unittest.TesterHost; -import org.junit.Assert; -import org.junit.Test; public class TestPersistentManager { Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1738044&r1=1738043&r2=1738044&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Wed Apr 6 20:13:31 2016 @@ -102,6 +102,12 @@ and <code>host</code> attributes define as <code>TransientAttribute</code>. (kfujino) </fix> + <fix> + <bug>59269</bug>: Correct the implementation of + <code>PersistentManagerBase</code> so that <code>minIdleSwap</code> + functions as designed and sessions are swapped out to keep the active + session count below <code>maxActiveSessions</code>. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> Modified: tomcat/tc8.5.x/trunk/webapps/docs/config/manager.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/config/manager.xml?rev=1738044&r1=1738043&r2=1738044&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/webapps/docs/config/manager.xml (original) +++ tomcat/tc8.5.x/trunk/webapps/docs/config/manager.xml Wed Apr 6 20:13:31 2016 @@ -215,21 +215,21 @@ </attribute> <attribute name="maxIdleSwap" required="false"> - <p>The time interval (in seconds) since the last access to a session - before it should be persisted to the session store, and - passivated out of the server's memory, or <code>-1</code> to disable - this feature. If this feature is enabled, the time interval specified - here should be equal to or longer than the value specified for - <code>maxIdleBackup</code>. By default, this feature is disabled.</p> + <p>The maximum time a session may be idle before it is eligible to be + swapped to disk due to inactivity. Setting this to <code>-1</code> means + sessions should not be swapped out just because of inactivity. If this + feature is enabled, the time interval specified here should be equal to + or longer than the value specified for <code>maxIdleBackup</code>. By + default, this feature is disabled.</p> </attribute> <attribute name="minIdleSwap" required="false"> - <p>The time interval (in seconds) since the last access to a session - before it will be eligible to be persisted to the session store, and - passivated out of the server's memory, or <code>-1</code> for this - swapping to be available at any time. If specified, this value should - be less than that specified by <code>maxIdleSwap</code>. By default, - this value is set to <code>-1</code>.</p> + <p>The minimum time in seconds a session must be idle before it is + eligible to be swapped to disk to keep the active session count below + maxActiveSessions. Setting to <code>-1</code> means sessions will not be + swapped out to keep the active session count down. If specified, this + value should be less than that specified by <code>maxIdleSwap</code>. + By default, this value is set to <code>-1</code>.</p> </attribute> <attribute name="processExpiresFrequency" required="false"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org