Author: markt
Date: Thu Oct 29 14:54:00 2009
New Revision: 830980

URL: http://svn.apache.org/viewvc?rev=830980&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47161
Make maxThreads return consistent. Will still return -1 in many cases but that 
is better than previously.
Note: Also ensures new return values don't break keep-alive auto-disable for 
the BIO HTTP connector.

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Thu Oct 29 14:54:00 2009
@@ -323,23 +323,6 @@
   +1: rjung, pero
   -1: 
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47161
-  Make maxThreads return consistent. Will still return -1 in many cases but 
that
-  is better than previously.
-  https://issues.apache.org/bugzilla/attachment.cgi?id=24341&action=edit
-  +1: markt, kkolinko, rjung
-  -1:
-  kkolinko: (We need to make some decision regarding the following lines in 
Http11Processor#process():
-        int threadRatio = (endpoint.getCurrentThreadsBusy() * 100)
-                / endpoint.getMaxThreads();
-    When JIoEndpoint uses an executor this value that was (-100) will now be 
(+100).
-    I am in favour of using the (threadRatio <= 75) branch when threadRatio
-    cannot be reliably calculated.
-
-    Besides that, I see no problems with this patch.
-  rjung: me to (threadRatio <= 75 branch).
-  )
-
 * Fix memory leak causes by a JRE implementation change in 1.6.0_15 onwards
   http://svn.apache.org/viewvc?view=revision&revision=828196
   http://svn.apache.org/viewvc?view=revision&revision=830378

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Processor.java Thu 
Oct 29 14:54:00 2009
@@ -774,10 +774,15 @@
         int keepAliveLeft = maxKeepAliveRequests;
         int soTimeout = endpoint.getSoTimeout();
 
-        int threadRatio = (endpoint.getCurrentThreadsBusy() * 100)
-                / endpoint.getMaxThreads();
-        if (threadRatio > 75) {
-            keepAliveLeft = 1;
+        // When using an executor, these values may return non-positive values
+        int curThreads = endpoint.getCurrentThreadsBusy();
+        int maxThreads = endpoint.getMaxThreads();
+        if (curThreads > 0 && maxThreads >0) {
+            // Only auto-disable keep-alive if the current thread usage % can 
be
+            // calculated correctly
+            if (curThreads*100/maxThreads > 75) {
+                keepAliveLeft = 1;
+            }
         }
         
         try {

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Thu 
Oct 29 14:54:00 2009
@@ -36,7 +36,6 @@
 import org.apache.tomcat.jni.SSLSocket;
 import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.jni.Status;
-import org.apache.tomcat.util.net.JIoEndpoint.Worker;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -188,7 +187,13 @@
             }
         }
     }
-    public int getMaxThreads() { return maxThreads; }
+    public int getMaxThreads() {
+        if (executor != null) {
+            return -1;
+        } else {
+            return maxThreads;
+        }
+    }
 
 
     /**
@@ -539,7 +544,7 @@
      * @return the amount of threads that are managed by the pool
      */
     public int getCurrentThreadCount() {
-        if (executor!=null) {
+        if (executor != null) {
             return -1;
         } else {
             return curThreads;

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Thu 
Oct 29 14:54:00 2009
@@ -160,7 +160,13 @@
             }
         }
     }
-    public int getMaxThreads() { return maxThreads; }
+    public int getMaxThreads() {
+        if (executor != null) {
+            return -1;
+        } else {
+            return maxThreads;
+        }
+    }
 
 
     /**

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu 
Oct 29 14:54:00 2009
@@ -57,7 +57,6 @@
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
-import org.apache.tomcat.util.net.JIoEndpoint.Worker;
 import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
 import org.apache.tomcat.util.net.jsse.NioX509KeyManager;
 import org.apache.tomcat.util.res.StringManager;
@@ -371,7 +370,17 @@
             }
         }
     }
-    public int getMaxThreads() { return maxThreads; }
+    public int getMaxThreads() {
+        if (running && getUseExecutor() && executor!=null) {
+            if (executor instanceof ThreadPoolExecutor) {
+                return ((ThreadPoolExecutor)executor).getMaximumPoolSize();
+            } else {
+                return -1;
+            }
+        } else {
+            return maxThreads;
+        }
+    }
 
 
     /**

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=830980&r1=830979&r2=830980&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Thu Oct 29 14:54:00 2009
@@ -319,6 +319,10 @@
         (markt)
       </fix>
       <fix>
+        <bug>47161</bug>: Report thread count correctly in Manager when 
exectors
+        are used and return -1 when it can not easily be determined. (markt)
+      </fix>
+      <fix>
         <bug>47235</bug>: Remove use of autoReconnect from MySQL examples.
         (markt)
       </fix>



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

Reply via email to