Hi All,

        Hope everyone has a nice weekend.

        Attached is a patch to record the maximum and current active number 
        of requests being processed by Cocoon. This information is printed in
        the debug section of every request. The idea is to get some gauge as
        to how many requests are being processed by the system simultaneously
        for load testing, etc.

        Hope it's all ok.

        Cheers,

        Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   Open Software Associates GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'     Email : [EMAIL PROTECTED]
          &&&&.        Business Hours : +49 69 9757 200
    &&&&&&&:

Index: src/org/apache/cocoon/Cocoon.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.9.2.15
diff -u -r1.9.2.15 Cocoon.java
--- src/org/apache/cocoon/Cocoon.java   2001/08/29 17:55:51     1.9.2.15
+++ src/org/apache/cocoon/Cocoon.java   2001/09/07 17:40:51
@@ -87,6 +87,12 @@
     /** flag for disposed or not */
     private boolean disposed = false;
 
+    /** active request count */
+    private static int activeRequestCount = 0;
+
+    /** maximum request count */
+    private static int maxRequestCount = 0;
+
     /** Create a new <code>Cocoon</code> instance. */
     public Cocoon() throws ConfigurationException {
         // Set the system properties needed by Xalan2.
@@ -347,71 +353,71 @@
     protected void debug(Environment environment,
                          StreamPipeline pipeline,
                          EventPipeline eventPipeline) {
-        if (this.getLogger().isDebugEnabled() == true) {
-            String lineSeparator = System.getProperty("line.separator");
-            Map objectModel = environment.getObjectModel();
-            Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
-            Session session = request.getSession(false);
-            StringBuffer msg = new StringBuffer();
-            msg.append("DEBUGGING INFORMATION:").append(lineSeparator);
-            if (pipeline != null && eventPipeline != null) {
-                msg.append("INTERNAL ");
+        String lineSeparator = System.getProperty("line.separator");
+        Map objectModel = environment.getObjectModel();
+        Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
+        Session session = request.getSession(false);
+        StringBuffer msg = new StringBuffer();
+        msg.append("DEBUGGING INFORMATION:").append(lineSeparator);
+        if (pipeline != null && eventPipeline != null) {
+            msg.append("INTERNAL ");
+        }
+        msg.append("REQUEST: 
+").append(request.getRequestURI()).append(lineSeparator).append(lineSeparator);
+        msg.append("CONTEXT PATH: 
+").append(request.getContextPath()).append(lineSeparator);
+        msg.append("SERVLET PATH: 
+").append(request.getServletPath()).append(lineSeparator);
+        msg.append("PATH INFO: 
+").append(request.getPathInfo()).append(lineSeparator).append(lineSeparator);
+
+        msg.append("REMOTE HOST: 
+").append(request.getRemoteHost()).append(lineSeparator);
+        msg.append("REMOTE ADDRESS: 
+").append(request.getRemoteAddr()).append(lineSeparator);
+        msg.append("REMOTE USER: 
+").append(request.getRemoteUser()).append(lineSeparator);
+        msg.append("REQUEST SESSION ID: 
+").append(request.getRequestedSessionId()).append(lineSeparator);
+        msg.append("REQUEST PREFERRED LOCALE: 
+").append(request.getLocale().toString()).append(lineSeparator);
+        msg.append("SERVER HOST: 
+").append(request.getServerName()).append(lineSeparator);
+        msg.append("SERVER PORT: 
+").append(request.getServerPort()).append(lineSeparator).append(lineSeparator);
+
+        msg.append("METHOD: ").append(request.getMethod()).append(lineSeparator);
+        msg.append("CONTENT LENGTH: 
+").append(request.getContentLength()).append(lineSeparator);
+        msg.append("PROTOCOL: ").append(request.getProtocol()).append(lineSeparator);
+        msg.append("SCHEME: ").append(request.getScheme()).append(lineSeparator);
+        msg.append("AUTH TYPE: 
+").append(request.getAuthType()).append(lineSeparator).append(lineSeparator);
+        msg.append("CURRENT ACTIVE REQUESTS: 
+").append(activeRequestCount).append(lineSeparator);
+        msg.append("MAXIMUM ACTIVE REQUESTS: 
+").append(maxRequestCount).append(lineSeparator).append(lineSeparator);
+
+        // log all of the request parameters
+        Enumeration e = request.getParameterNames();
+
+        msg.append("REQUEST 
+PARAMETERS:").append(lineSeparator).append(lineSeparator);
+
+        while (e.hasMoreElements()) {
+            String p = (String) e.nextElement();
+
+            msg.append("PARAM: '").append(p).append("' ")
+               .append("VALUES: '");
+            String[] params = request.getParameterValues(p);
+            for (int i = 0; i < params.length; i++) {
+                msg.append("["+params[i]+"]");
+                if (i != params.length-1) 
+                msg.append(", ");
             }
-            msg.append("REQUEST: 
").append(request.getRequestURI()).append(lineSeparator).append(lineSeparator);
-            msg.append("CONTEXT PATH: 
").append(request.getContextPath()).append(lineSeparator);
-            msg.append("SERVLET PATH: 
").append(request.getServletPath()).append(lineSeparator);
-            msg.append("PATH INFO: 
").append(request.getPathInfo()).append(lineSeparator).append(lineSeparator);
-
-            msg.append("REMOTE HOST: 
").append(request.getRemoteHost()).append(lineSeparator);
-            msg.append("REMOTE ADDRESS: 
").append(request.getRemoteAddr()).append(lineSeparator);
-            msg.append("REMOTE USER: 
").append(request.getRemoteUser()).append(lineSeparator);
-            msg.append("REQUEST SESSION ID: 
").append(request.getRequestedSessionId()).append(lineSeparator);
-            msg.append("REQUEST PREFERRED LOCALE: 
").append(request.getLocale().toString()).append(lineSeparator);
-            msg.append("SERVER HOST: 
").append(request.getServerName()).append(lineSeparator);
-            msg.append("SERVER PORT: 
").append(request.getServerPort()).append(lineSeparator).append(lineSeparator);
-
-            msg.append("METHOD: ").append(request.getMethod()).append(lineSeparator);
-            msg.append("CONTENT LENGTH: 
").append(request.getContentLength()).append(lineSeparator);
-            msg.append("PROTOCOL: 
").append(request.getProtocol()).append(lineSeparator);
-            msg.append("SCHEME: ").append(request.getScheme()).append(lineSeparator);
-            msg.append("AUTH TYPE: 
").append(request.getAuthType()).append(lineSeparator).append(lineSeparator);
+
+            msg.append("'").append(lineSeparator);
+        }
 
-            // log all of the request parameters
-            Enumeration e = request.getParameterNames();
+        msg.append(lineSeparator).append("SESSION 
+ATTRIBUTES:").append(lineSeparator).append(lineSeparator);
 
-            msg.append("REQUEST 
PARAMETERS:").append(lineSeparator).append(lineSeparator);
+        // log all of the session attributes
+        if (session != null) {
+             e = session.getAttributeNames();
 
             while (e.hasMoreElements()) {
                 String p = (String) e.nextElement();
-
-                 msg.append("PARAM: '").append(p).append("' ")
-                    .append("VALUES: '");
-                String[] params = request.getParameterValues(p);
-                for (int i = 0; i < params.length; i++) {
-                    msg.append("["+params[i]+"]");
-                    if (i != params.length-1) 
-                        msg.append(", ");
-                }
-                    
-                msg.append("'").append(lineSeparator);
-            }
-
-            msg.append(lineSeparator).append("SESSION 
ATTRIBUTES:").append(lineSeparator).append(lineSeparator);
 
-            // log all of the session attributes
-            if (session != null) {
-                 e = session.getAttributeNames();
-
-                while (e.hasMoreElements()) {
-                    String p = (String) e.nextElement();
-
-                    msg.append("PARAM: '").append(p).append("' ")
-                       .append("VALUE: 
'").append(session.getAttribute(p)).append("'").append(lineSeparator);
-                }
+                msg.append("PARAM: '").append(p).append("' ")
+                   .append("VALUE: 
+'").append(session.getAttribute(p)).append("'").append(lineSeparator);
             }
-
-            getLogger().debug(msg.toString());
         }
+
+        getLogger().debug(msg.toString());
     }
 
     /**
@@ -420,9 +426,18 @@
     public boolean process(Environment environment)
     throws Exception {
         if (disposed) throw new IllegalStateException("You cannot process a Disposed 
Cocoon engine.");
-        this.debug(environment, null, null);
-        return this.sitemapManager.invoke(this.componentManager, environment, "", 
this.sitemapFileName,
-                 this.checkSitemapReload, this.reloadSitemapAsynchron);
+
+       try {
+            if (this.getLogger().isDebugEnabled()) {
+                incRequestCount();
+                this.debug(environment, null, null);
+            }
+            return this.sitemapManager.invoke(this.componentManager, environment, "", 
+this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron);
+        } finally {
+            if (this.getLogger().isDebugEnabled()) {
+                decRequestCount();
+            }
+       }
     }
 
     /**
@@ -432,10 +447,18 @@
     public boolean process(Environment environment, StreamPipeline pipeline, 
EventPipeline eventPipeline)
     throws Exception {
         if (disposed) throw new IllegalStateException("You cannot process a Disposed 
Cocoon engine.");
-        this.debug(environment, pipeline, eventPipeline);
-        return this.sitemapManager.invoke(this.componentManager, environment, "", 
this.sitemapFileName,
-              this.checkSitemapReload, this.reloadSitemapAsynchron,
-              pipeline, eventPipeline);
+
+       try {
+            if (this.getLogger().isDebugEnabled()) {
+                incRequestCount();
+                this.debug(environment, pipeline, eventPipeline);
+            }
+            return this.sitemapManager.invoke(this.componentManager, environment, "", 
+this.sitemapFileName, this.checkSitemapReload, this.reloadSitemapAsynchron, pipeline, 
+eventPipeline);
+        } finally {
+            if (this.getLogger().isDebugEnabled()) {
+                decRequestCount();
+            }
+       }
     }
 
     /**
@@ -502,4 +525,21 @@
             if (sourceHandler != null) this.componentManager.release((Component) 
sourceHandler);
         }
     }
+
+    /**
+     * Increment active request count for incoming requests, and save this
+     * result if it's the maximum.
+     */
+    private static synchronized void incRequestCount() {
+       if (++activeRequestCount > maxRequestCount)
+           maxRequestCount = activeRequestCount;
+    }
+
+    /**
+     * Decrement active request count.
+     */
+    private static synchronized void decRequestCount() {
+       --activeRequestCount;
+    }
+
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to