You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/09/09 23:30:29 UTC

svn commit: r1167368 - /tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java

Author: kkolinko
Date: Fri Sep  9 21:30:28 2011
New Revision: 1167368

URL: http://svn.apache.org/viewvc?rev=1167368&view=rev
Log:
Reviewing r1166576...
Improve performance of Http11Processor.disableKeepAlive(): call getMaxThreads() first and do not call getCurrentThreadsBusy() twice,
because ThreadPoolExecutor.getActiveCount() in JRE is implemented as a loop that counts threads and that should be expensive.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1167368&r1=1167367&r2=1167368&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Fri Sep  9 21:30:28 2011
@@ -121,14 +121,14 @@ public class Http11Processor extends Abs
     @Override
     protected boolean disableKeepAlive() {
         int threadRatio = -1;   
-        // These may return zero or negative values     
-        // Only calculate a thread ratio when both are >0 to ensure we get a    
-        // sensible result      
-        if (endpoint.getCurrentThreadsBusy() >0 &&      
-                endpoint.getMaxThreads() >0) {      
-            threadRatio = (endpoint.getCurrentThreadsBusy() * 100)      
-                    / endpoint.getMaxThreads();     
-        }   
+        // These may return zero or negative values
+        // Only calculate a thread ratio when both are >0 to ensure we get a
+        // sensible result
+        int maxThreads, threadsBusy;
+        if ((maxThreads = endpoint.getMaxThreads()) > 0
+                && (threadsBusy = endpoint.getCurrentThreadsBusy()) > 0) {
+            threadRatio = (threadsBusy * 100) / maxThreads;
+        }
         // Disable keep-alive if we are running low on threads      
         if (threadRatio > getDisableKeepAlivePercentage()) {     
             return true;



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