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...@locus.apache.org on 2000/05/24 18:34:24 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util Ascii.java DateTool.java

costin      00/05/24 09:34:23

  Modified:    src/share/org/apache/tomcat/core Request.java
                        RequestImpl.java
               src/share/org/apache/tomcat/facade
                        HttpServletRequestFacade.java
               src/share/org/apache/tomcat/request SessionInterceptor.java
               src/share/org/apache/tomcat/service/http
                        HttpRequestAdapter.java HttpResponseAdapter.java
               src/share/org/apache/tomcat/util Ascii.java DateTool.java
  Log:
  Removing hot-spots:
  
  - Use memory-efficient methods to access cookies ( count, indexed access instead of
  creating Cookie[] ). The facade will implement the servlet API method returning
  [], internally we use the efficient ones.
  
  - Another ( not so usefull ) Http adapter optimization: recycle the buffered stream,
  avoid 2K per request.
  
  - Another one: HTTP 0.9 is the only one without protocol, no need to compare.
  
  - Temp. change - don't display Date: header in response, I'll put it back after I
  find a better way to convert date to string ( now the conversion allocates 30% of the GC)
  -  BTW, lastModified() is now responsible for 60% of allocations ( after removing 30% date),
  again - disable reloading for performance sites.
  
  Revision  Changes    Path
  1.40      +2 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Request.java	2000/05/23 21:39:51	1.39
  +++ Request.java	2000/05/24 16:34:06	1.40
  @@ -112,7 +112,8 @@
   
       //-------------------- "Computed" properties --------------------
       // ( directly derived from headers or request paths )
  -
  +    public Cookie getCookie( int idx );
  +    public int getCookieCount();
       /** Return the cookies
        */
       public Cookie[] getCookies() ;
  
  
  
  1.41      +16 -8     jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java
  
  Index: RequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- RequestImpl.java	2000/05/24 04:41:50	1.40
  +++ RequestImpl.java	2000/05/24 16:34:07	1.41
  @@ -418,23 +418,31 @@
       }
   
       // --------------------
  -    public Cookie[] getCookies() {
  -	// XXX need to use Cookie[], Vector is not needed
  +    public int getCookieCount() {
   	if( ! didCookies ) {
  -	    // XXX need a better test
  -	    // XXX need to use adapter for hings
   	    didCookies=true;
   	    RequestUtil.processCookies( this, cookies );
   	}
  +	return cookies.size();
  +    }
   
  -	Cookie[] cookieArray = new Cookie[cookies.size()];
  +    public Cookie getCookie( int idx ) {
  +	if( ! didCookies ) {
  +	    didCookies=true;
  +	    RequestUtil.processCookies( this, cookies );
  +	}
  +	return (Cookie)cookies.elementAt(idx);
  +    }
  +    
  +    public Cookie[] getCookies() {
  +	int count=request.getCookieCount();
  +	Cookie[] cookieArray = new Cookie[ count ];
   
  -	for (int i = 0; i < cookies.size(); i ++) {
  -	    cookieArray[i] = (Cookie)cookies.elementAt(i);
  +	for (int i = 0; i < count; i ++) {
  +	    cookieArray[i] = request.getCookie( i );
   	}
   
   	return cookieArray;
  -	//        return cookies;
       }
       // -------------------- LookupResult
       public ServletWrapper getWrapper() {
  
  
  
  1.3       +8 -1      jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpServletRequestFacade.java	2000/05/23 20:58:22	1.2
  +++ HttpServletRequestFacade.java	2000/05/24 16:34:09	1.3
  @@ -140,7 +140,14 @@
       }
   
       public Cookie[] getCookies() {
  -	return request.getCookies();
  +	int count=request.getCookieCount();
  +	Cookie[] cookieArray = new Cookie[ count ];
  +
  +	for (int i = 0; i < count; i ++) {
  +	    cookieArray[i] = request.getCookie( i );
  +	}
  +
  +	return cookieArray;
       }
   
       /** Tomcat Request doesn't deal with header to date conversion.
  
  
  
  1.21      +3 -3      jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java
  
  Index: SessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- SessionInterceptor.java	2000/05/12 19:36:53	1.20
  +++ SessionInterceptor.java	2000/05/24 16:34:11	1.21
  @@ -136,12 +136,12 @@
       public int requestMap(Request request ) {
   	String sessionId = null;
   
  -	Cookie cookies[]=request.getCookies(); // assert !=null
  +	int count=request.getCookieCount();
   	
   	// Give priority to cookies. I don't know if that's part
   	// of the spec - XXX
  -	for( int i=0; i<cookies.length; i++ ) {
  -	    Cookie cookie = cookies[i];
  +	for( int i=0; i<count; i++ ) {
  +	    Cookie cookie = request.getCookie(i);
   	    
   	    if (cookie.getName().equals("JSESSIONID")) {
   		sessionId = cookie.getValue();
  
  
  
  1.13      +23 -9     jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java
  
  Index: HttpRequestAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- HttpRequestAdapter.java	2000/05/24 04:41:55	1.12
  +++ HttpRequestAdapter.java	2000/05/24 16:34:14	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v 1.12 2000/05/24 04:41:55 costin Exp $
  - * $Revision: 1.12 $
  - * $Date: 2000/05/24 04:41:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v 1.13 2000/05/24 16:34:14 costin Exp $
  + * $Revision: 1.13 $
  + * $Date: 2000/05/24 16:34:14 $
    *
    * ====================================================================
    *
  @@ -72,16 +72,28 @@
   import javax.servlet.*;
   import javax.servlet.http.*;
   
  +class RecycleBufferedInputStream extends BufferedInputStream {
  +    RecycleBufferedInputStream( InputStream is ) {
  +	super( is );
  +    }
  +
  +    void setInputStream( InputStream is ) {
  +	this.in=is;
  +    }
  +
  +    
  +}
  +
   public class HttpRequestAdapter extends RequestImpl {
       private Socket socket;
       private boolean moreRequests = false;
  -    InputStream sin;
  +    RecycleBufferedInputStream sin;
       byte[] buf;
       int bufSize=2048; // default
       int off=0;
       int count=0;
       public static final String DEFAULT_CHARACTER_ENCODING = "8859_1";
  -
  +    
       
       public HttpRequestAdapter() {
           super();
  @@ -89,7 +101,10 @@
       }
   
       public void setSocket(Socket socket) throws IOException {
  -	sin = new BufferedInputStream ( socket.getInputStream());
  +	if( sin==null)
  +	    sin = new RecycleBufferedInputStream ( socket.getInputStream());
  +	else
  +	    sin.setInputStream( socket.getInputStream());
   	in = new BufferedServletInputStream(this);
           this.socket = socket;
       	moreRequests = true;
  @@ -128,8 +143,7 @@
   	processRequestLine(response  );
   
   	// for 0.9, we don't have headers!
  -	if ((protocol!=null) &&
  -            !protocol.toLowerCase().startsWith("http/0.")) {
  +	if (protocol!=null) { // all HTTP versions with protocol also have headers ( 0.9 has no HTTP/0.9 !)
   	    readHeaders( headers, in  );
   	}
   
  @@ -361,7 +375,7 @@
   	    queryString = new String( buf, qryIdx+1, endReq - qryIdx -1 );
   	}
   
  -	System.out.println("XXX " + method + " " + requestURI + " " + queryString + " " + protocol );
  +	//	System.out.println("XXX " + method + " " + requestURI + " " + queryString + " " + protocol );
   
       }
   
  
  
  
  1.11      +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java
  
  Index: HttpResponseAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HttpResponseAdapter.java	2000/05/23 21:39:53	1.10
  +++ HttpResponseAdapter.java	2000/05/24 16:34:15	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.10 2000/05/23 21:39:53 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/05/23 21:39:53 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.11 2000/05/24 16:34:15 costin Exp $
  + * $Revision: 1.11 $
  + * $Date: 2000/05/24 16:34:15 $
    *
    * ====================================================================
    *
  @@ -141,7 +141,7 @@
   	// This avoids redundant setting of date ( very expensive ).
   	// XXX XXX Check if IIS, NES do generate the date
   	MimeHeaderField dateH= headers.find( "Date" );
  -	if( dateH == null ) {
  +	if( false && dateH == null ) {
   	    // no date header set by user
   	    dateH=headers.putHeader();
   	    dateH.setName("Date");
  
  
  
  1.3       +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/util/Ascii.java
  
  Index: Ascii.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Ascii.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Ascii.java	2000/02/14 04:59:42	1.2
  +++ Ascii.java	2000/05/24 16:34:20	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Ascii.java,v 1.2 2000/02/14 04:59:42 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/02/14 04:59:42 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Ascii.java,v 1.3 2000/05/24 16:34:20 costin Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/05/24 16:34:20 $
    *
    * ====================================================================
    *
  @@ -187,7 +187,8 @@
        */
   
       public static int parseInt(byte[] b, int off, int len)
  -    throws NumberFormatException {
  +	throws NumberFormatException
  +    {
           int c;
   
   	if (b == null || len <= 0 || !isDigit(c = b[off++])) {
  
  
  
  1.2       +4 -5      jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java
  
  Index: DateTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateTool.java	2000/05/24 01:58:17	1.1
  +++ DateTool.java	2000/05/24 16:34:20	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.1 2000/05/24 01:58:17 costin Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/24 01:58:17 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.2 2000/05/24 16:34:20 costin Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/05/24 16:34:20 $
    *
    * ====================================================================
    *
  @@ -107,8 +107,7 @@
       /** Pattern used for old cookies
        */
       public final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
  -    
  -    
  +
       /** DateFormat to be used to format dates
        */
       public final static SimpleDateFormat rfc1123Format =