You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2003/01/16 22:56:02 UTC

cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote RequestProcessor.java Request.java Response.java

costin      2003/01/16 13:56:02

  Modified:    coyote/src/java/org/apache/coyote Request.java Response.java
  Added:       coyote/src/java/org/apache/coyote RequestProcessor.java
  Log:
  Collect data about incoming/outgoing traffic, other per/request statistics.
  
  To avoid sync and keep things simple - we collect them in RequestProcessor,
  a per/thread structure.
  
  Revision  Changes    Path
  1.16      +24 -4     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Request.java	19 Sep 2002 06:39:43 -0000	1.15
  +++ Request.java	16 Jan 2003 21:56:02 -0000	1.16
  @@ -61,7 +61,6 @@
   package org.apache.coyote;
   
   import java.io.IOException;
  -import java.util.Enumeration;
   import java.util.Hashtable;
   
   import org.apache.tomcat.util.buf.ByteChunk;
  @@ -172,7 +171,8 @@
        */
       private int contentLength = -1;
       // how much body we still have to read.
  -    private int available = -1; 
  +    // Apparently nobody uses this field...
  +    private int available = -1;
       private MessageBytes contentTypeMB = null;
       private String charEncoding = null;
       private Cookies cookies = new Cookies(headers);
  @@ -184,6 +184,10 @@
   
       private Response response;
       private ActionHook hook;
  +
  +    private int bytesRead=0;
  +
  +    private RequestProcessor reqProcessorMX=new RequestProcessor(this);
       // ------------------------------------------------------------- Properties
   
   
  @@ -429,8 +433,10 @@
       public int doRead(ByteChunk chunk) 
           throws IOException {
           int n = inputBuffer.doRead(chunk, this);
  -        if (n > 0)
  +        if (n > 0) {
               available -= n;
  +            bytesRead+=n;
  +        }
           return n;
       }
   
  @@ -460,6 +466,9 @@
   
   
       public void recycle() {
  +        // Call RequestProcessorMX
  +        reqProcessorMX.updateCounters();
  +        bytesRead=0;
   
   	contentLength = -1;
           contentTypeMB = null;
  @@ -495,5 +504,16 @@
           attributes.clear();
       }
   
  +    // -------------------- Info  --------------------
  +    public RequestProcessor getRequestProcessor() {
  +        return reqProcessorMX;
  +    }
   
  -}
  +    public int getBytesRead() {
  +        return bytesRead;
  +    }
  +
  +    public void setBytesRead(int bytesRead) {
  +        this.bytesRead = bytesRead;
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.20      +16 -3     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Response.java	3 Dec 2002 16:37:59 -0000	1.19
  +++ Response.java	16 Jan 2003 21:56:02 -0000	1.20
  @@ -150,6 +150,9 @@
       protected int contentLength = -1;
       private Locale locale = DEFAULT_LOCALE;
   
  +    // General informations
  +    private long bytesWritten=0;
  +
       /**
        * Holds request error exception.
        */
  @@ -520,11 +523,12 @@
        * Write a chunk of bytes.
        */
       public void doWrite(ByteChunk chunk/*byte buffer[], int pos, int count*/)
  -        throws IOException {
  +        throws IOException
  +    {
           outputBuffer.doWrite(chunk, this);
  +        bytesWritten+=chunk.getLength();
       }
   
  -
       // --------------------
       
       public void recycle() {
  @@ -540,7 +544,16 @@
           errorException = null;
           errorURI = null;
           headers.clear();
  -        
  +
  +        // update counters
  +        bytesWritten=0;
       }
   
  +    public long getBytesWritten() {
  +        return bytesWritten;
  +    }
  +
  +    public void setBytesWritten(long bytesWritten) {
  +        this.bytesWritten = bytesWritten;
  +    }
   }
  
  
  
  1.1                  jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/RequestProcessor.java
  
  Index: RequestProcessor.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.coyote;
  
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Hashtable;
  
  import org.apache.tomcat.util.buf.ByteChunk;
  import org.apache.tomcat.util.buf.MessageBytes;
  import org.apache.tomcat.util.buf.UDecoder;
  
  import org.apache.tomcat.util.http.MimeHeaders;
  import org.apache.tomcat.util.http.Parameters;
  import org.apache.tomcat.util.http.ContentType;
  import org.apache.tomcat.util.http.Cookies;
  
  /**
   * Structure holding the Request and Response objects. It also holds statistical
   * informations about request processing and provide management informations
   * about the requests beeing processed.
   *
   * Each thread uses a Request/Response pair that is recycled on each request.
   * This object provides a place to collect global low-level statistics - without
   * having to deal with synchronization ( since each thread will have it's own
   * RequestProcessorMX ).
   *
   * TODO: Request notifications will be registered here.
   *
   * @author Costin Manolache
   */
  public class RequestProcessor  {
  
  
      // ----------------------------------------------------------- Constructors
  
      public RequestProcessor(Request req) {
          this.req=req;
      }
  
  
      // ----------------------------------------------------- Instance Variables
      Request req;
      Response res;
  
      // -------------------- Information about the current request  -----------
      // This is usefull for long-running requests only
  
      public String getCurrentUri() {
          return req.requestURI().toString();
      }
  
      public String getCurrentQueryString() {
          return req.queryString().toString();
      }
  
      public String getProtocol() {
          return req.protocol().toString();
      }
  
      public String getVirtualHost() {
          return req.serverName().toString();
      }
  
      public int getServerPort() {
          return req.getServerPort();
      }
  
      public String getRemoteAddr() {
          return req.remoteAddr().toString();
      }
  
      public int getContentLength() {
          return req.getContentLength();
      }
  
      // -------------------- Statistical data  --------------------
      // Collected at the end of each request.
      private long bytesSent;
      private long bytesReceived;
  
      // Total time = divide by requestCount to get average.
      private long processingTime;
      // The longest response time for a request
      private long maxTime;
      // URI of the request that took maxTime
      private String maxRequestUri;
  
      private int requestCount;
      // number of response codes >= 400
      private int errorCount;
  
  
      /** Called by the processor before recycling the request. It'll collect
       * statistic information.
       */
      public void updateCounters() {
          bytesReceived+=req.getBytesRead();
          bytesSent+=req.getResponse().getBytesWritten();
      }
  
      public long getBytesSent() {
          return bytesSent;
      }
  
      public void setBytesSent(long bytesSent) {
          this.bytesSent = bytesSent;
      }
  
      public long getBytesReceived() {
          return bytesReceived;
      }
  
      public void setBytesReceived(long bytesReceived) {
          this.bytesReceived = bytesReceived;
      }
  
      public long getProcessingTime() {
          return processingTime;
      }
  
      public void setProcessingTime(long processingTime) {
          this.processingTime = processingTime;
      }
  
      public long getMaxTime() {
          return maxTime;
      }
  
      public void setMaxTime(long maxTime) {
          this.maxTime = maxTime;
      }
  
      public String getMaxRequestUri() {
          return maxRequestUri;
      }
  
      public void setMaxRequestUri(String maxRequestUri) {
          this.maxRequestUri = maxRequestUri;
      }
  
      public int getRequestCount() {
          return requestCount;
      }
  
      public void setRequestCount(int requestCount) {
          this.requestCount = requestCount;
      }
  
      public int getErrorCount() {
          return errorCount;
      }
  
      public void setErrorCount(int errorCount) {
          this.errorCount = errorCount;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote RequestProcessor.java Request.java Response.java

Posted by Remy Maucherat <re...@apache.org>.
costin@apache.org wrote:
> costin      2003/01/16 13:56:02
> 
>   Modified:    coyote/src/java/org/apache/coyote Request.java Response.java
>   Added:       coyote/src/java/org/apache/coyote RequestProcessor.java
>   Log:
>   Collect data about incoming/outgoing traffic, other per/request statistics.
>   
>   To avoid sync and keep things simple - we collect them in RequestProcessor,
>   a per/thread structure.

That's neat. I was wondering how to do something like the APache server 
status (which I like). Of course, if it *also* can be accessed using 
JMX, it rocks ;-)

Remy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>