You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Pilho Kim <ph...@math.soongsil.ac.kr> on 2000/07/30 16:53:05 UTC

This would be a nice patch for Tomcat 3.3 dev.

Hi,

Is your nightly Tomcat slow, isn't it?
Or do you meet, sometimes, such errors as

<---------- error --------------------------------->
2000-07-30 11:36:42 - Context: IOException in R( /examples +
/jsp/snp/snoop.jsp
+ null) - java.net.SocketException: Connection reset by peer: socket write
error

        at java.net.SocketOutputStream.socketWrite(Native Method)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
        at
org.apache.tomcat.service.http.HttpResponseAdapter.endHeaders(HttpRes
ponseAdapter.java:126)
        at
org.apache.tomcat.core.BufferedServletOutputStream.sendHeaders(Buffer
edServletOutputStream.java:126)
        at
org.apache.tomcat.core.BufferedServletOutputStream.reallyFlush(Buffer
edServletOutputStream.java:239)
        at
org.apache.tomcat.core.ResponseImpl.finish(ResponseImpl.java:198)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:670
)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
n(HttpConnectionHandler.java:195)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
393)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java
:507)
        at java.lang.Thread.run(Thread.java:484)
<-------------------------------------------------->


I hope that the following patch would be nice for Tomcat 3.3.
I have removed the tow lines

	sout.write( buffer, 0, bufferCount );
	sout.flush();

in the method endHeaders() of HttpResponseAdapter.java

After applying the patch, Tomecat works more faster
and the above error does not occur.

Thanks

Kim, Pilho

 

$Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/
service/http/HttpResponseAdapter.java,v 1.12 2000/07/11 03:48:58 alex Exp
$
$Revision: 1.12 $
$Date: 2000/07/11 03:48:58 $

    public void endHeaders()  throws IOException {
	super.endHeaders();
	
	sendStatus( status, ResponseImpl.getMessage( status ));

	int count=headers.size();
	for( int i=0; i<count; i++ ) {
	    MimeHeaderField field=headers.getField( i );
	    // response headers are set by the servlet, so probably we
have only
	    // Strings.
	    // XXX date, cookies, etc shoud be extracted from response
	    printHead( field.getName() );
	    printHead(": ");
	    printHead( field.getValue() );
	    printHead("\r\n");
	}
	
	printHead( "\r\n" );

-	sout.write( buffer, 0, bufferCount );
-	sout.flush();
    }




Re: This would be a nice patch for Tomcat 3.3 dev.

Posted by Costin Manolache <co...@eng.sun.com>.
Hi Pilho,


> I recommend that
>      (1) you use char[] buffer instead of byte[] buffer
>   or (2) you use buffer as a byte array of UTF8 characters.
>
> How about that?

Yes, using only one char buffer may be an idea, but it seems a
bit confusing even as a start, and it may be hard to implement
it in a clean way.

Also, byte[] can be directly used with the native methods
in Apache and can be passed to the WebServer.

The main problem is converting from UTF8 in the
user charset - and using char[] doesn't solve this problem.

I'll try to check in your patches as soon as I find some time.

Costin

>
> Kim
>
> On Sun, 30 Jul 2000 cmanolache@yahoo.com wrote:
>
> > Hi,
> >
> > I understand your patch, better char-byte conversion is a big priority for
> > me, but I would like a general solution that is more memory and
> > speed efficient. new String(byte[] ) and String.getBytes() seem very bad
> > for both.
> >
> > I'm not -1 on this patch - but I'll try to find a solution that can apply
> > in all other cases.
> >
> > Costin
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: This would be a nice patch for Tomcat 3.3 dev.

Posted by Pilho Kim <ph...@math.soongsil.ac.kr>.
Hi, Costin

I recommend that 
     (1) you use char[] buffer instead of byte[] buffer
  or (2) you use buffer as a byte array of UTF8 characters.

How about that?

Kim


On Sun, 30 Jul 2000 cmanolache@yahoo.com wrote:

> Hi,
> 
> I understand your patch, better char-byte conversion is a big priority for
> me, but I would like a general solution that is more memory and
> speed efficient. new String(byte[] ) and String.getBytes() seem very bad
> for both.
> 
> I'm not -1 on this patch - but I'll try to find a solution that can apply
> in all other cases.
> 
> Costin
> 


Re: This would be a nice patch for Tomcat 3.3 dev.

Posted by cm...@yahoo.com.
Hi,

I understand your patch, better char-byte conversion is a big priority for
me, but I would like a general solution that is more memory and
speed efficient. new String(byte[] ) and String.getBytes() seem very bad
for both.

I'm not -1 on this patch - but I'll try to find a solution that can apply
in all other cases.

Costin


On Mon, 31 Jul 2000, Pilho Kim wrote:

> Hi, tomcat developers
> 
> For faster working of Tomcat v3.3 dev,
> the following patch is needed, too.
> The patch supports, also, multi-byte characters (e.g. EUC-KR).
> 
> Thanks
> Kim, Pilho
> 
> 
> CVS repository:
> 
> $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat
> /service/http/HttpResponseAdapter.java,v 1.12 2000/07/11 03:48:58 alex Exp
> $
> $Revision: 1.12 $
> $Date: 2000/07/11 03:48:58 $
> 
> [-------------  begin of patch  ---------------]
> 
>     // From BufferedServletOutputStream
>     // XXX will be moved in a new in/out system, temp. code
>     // Right now it's not worse than BOS
>     protected void printHead( String s ) {
> 	if (s==null) s="null";
> 
> -	int len = s.length();
> -	for (int i = 0; i < len; i++) {
> -	    char c = s.charAt (i);
> -	    
> -	    //
> -	    // XXX NOTE:  This is clearly incorrect for many strings,
> -	    // but is the only consistent approach within the current
> -	    // servlet framework.  It must suffice until servlet output
> -	    // streams properly encode their output.
> -	    //
> -	    if ((c & 0xff00) != 0) {	// high order byte must be zero
> -		// XXX will go away after we change the I/O system
> -		loghelper.log("Header character is not iso8859_1, not
> supported yet: " + c, Logger.ERROR ) ;
> -	    }
> -	    if( bufferCount >= buffer.length ) {
> -		byte bufferNew[]=new byte[ buffer.length * 2 ];
> -		System.arraycopy( buffer,0, bufferNew, 0, buffer.length );
> -		buffer=bufferNew;
> -	    }
> -	    buffer[bufferCount] = (byte)c;
> -	    bufferCount++;
> -	}
> +	byte[] buffer1 = s.getBytes();
> +	byte[] buffer2;
> +	if( bufferCount + buffer1.length > buffer.length ) {
> +	    buffer2 = new byte[buffer.length + buffer1.length];
> +	    System.arraycopy( buffer,0, buffer2, 0, buffer.length );
> +	    System.arraycopy( buffer1, 0, buffer2, buffer.length,
> buffer1.length );
> +	    buffer = buffer2;
> +	    bufferCount = bufferCount + buffer1.length;
> +	}
> +	else {
> +	    System.arraycopy( buffer1,0, buffer, bufferCount,
> buffer1.length );
> +	    bufferCount = bufferCount + buffer1.length;
> +	}
>    }
> 
> [-------------   end of patch   ---------------]
> 
> 
> 
> On Sun, 30 Jul 2000, Pilho Kim wrote:
> 
> > Hi,
> > 
> > Is your nightly Tomcat slow, isn't it?
> > Or do you meet, sometimes, such errors as
> > 
> > <---------- error --------------------------------->
> > 2000-07-30 11:36:42 - Context: IOException in R( /examples +
> > /jsp/snp/snoop.jsp
> > + null) - java.net.SocketException: Connection reset by peer: socket write
> > error
> > 
> >         at java.net.SocketOutputStream.socketWrite(Native Method)
> >         at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
> >         at
> > org.apache.tomcat.service.http.HttpResponseAdapter.endHeaders(HttpRes
> > ponseAdapter.java:126)
> >         at
> > org.apache.tomcat.core.BufferedServletOutputStream.sendHeaders(Buffer
> > edServletOutputStream.java:126)
> >         at
> > org.apache.tomcat.core.BufferedServletOutputStream.reallyFlush(Buffer
> > edServletOutputStream.java:239)
> >         at
> > org.apache.tomcat.core.ResponseImpl.finish(ResponseImpl.java:198)
> >         at
> > org.apache.tomcat.core.ContextManager.service(ContextManager.java:670
> > )
> >         at
> > org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
> > n(HttpConnectionHandler.java:195)
> >         at
> > org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
> > 393)
> >         at
> > org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java
> > :507)
> >         at java.lang.Thread.run(Thread.java:484)
> > <-------------------------------------------------->
> > 
> > 
> > I hope that the following patch would be nice for Tomcat 3.3.
> > I have removed the tow lines
> > 
> > 	sout.write( buffer, 0, bufferCount );
> > 	sout.flush();
> > 
> > in the method endHeaders() of HttpResponseAdapter.java
> > 
> > After applying the patch, Tomecat works more faster
> > and the above error does not occur.
> > 
> > Thanks
> > 
> > Kim, Pilho
> > 
> >  
> > 
> > $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/
> > service/http/HttpResponseAdapter.java,v 1.12 2000/07/11 03:48:58 alex Exp
> > $
> > $Revision: 1.12 $
> > $Date: 2000/07/11 03:48:58 $
> > 
> >     public void endHeaders()  throws IOException {
> > 	super.endHeaders();
> > 	
> > 	sendStatus( status, ResponseImpl.getMessage( status ));
> > 
> > 	int count=headers.size();
> > 	for( int i=0; i<count; i++ ) {
> > 	    MimeHeaderField field=headers.getField( i );
> > 	    // response headers are set by the servlet, so probably we
> > have only
> > 	    // Strings.
> > 	    // XXX date, cookies, etc shoud be extracted from response
> > 	    printHead( field.getName() );
> > 	    printHead(": ");
> > 	    printHead( field.getValue() );
> > 	    printHead("\r\n");
> > 	}
> > 	
> > 	printHead( "\r\n" );
> > 
> > -	sout.write( buffer, 0, bufferCount );
> > -	sout.flush();
> >     }
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 


Re: This would be a nice patch for Tomcat 3.3 dev.

Posted by Pilho Kim <ph...@math.soongsil.ac.kr>.
Hi, tomcat developers

For faster working of Tomcat v3.3 dev,
the following patch is needed, too.
The patch supports, also, multi-byte characters (e.g. EUC-KR).

Thanks
Kim, Pilho


CVS repository:

$Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat
/service/http/HttpResponseAdapter.java,v 1.12 2000/07/11 03:48:58 alex Exp
$
$Revision: 1.12 $
$Date: 2000/07/11 03:48:58 $

[-------------  begin of patch  ---------------]

    // From BufferedServletOutputStream
    // XXX will be moved in a new in/out system, temp. code
    // Right now it's not worse than BOS
    protected void printHead( String s ) {
	if (s==null) s="null";

-	int len = s.length();
-	for (int i = 0; i < len; i++) {
-	    char c = s.charAt (i);
-	    
-	    //
-	    // XXX NOTE:  This is clearly incorrect for many strings,
-	    // but is the only consistent approach within the current
-	    // servlet framework.  It must suffice until servlet output
-	    // streams properly encode their output.
-	    //
-	    if ((c & 0xff00) != 0) {	// high order byte must be zero
-		// XXX will go away after we change the I/O system
-		loghelper.log("Header character is not iso8859_1, not
supported yet: " + c, Logger.ERROR ) ;
-	    }
-	    if( bufferCount >= buffer.length ) {
-		byte bufferNew[]=new byte[ buffer.length * 2 ];
-		System.arraycopy( buffer,0, bufferNew, 0, buffer.length );
-		buffer=bufferNew;
-	    }
-	    buffer[bufferCount] = (byte)c;
-	    bufferCount++;
-	}
+	byte[] buffer1 = s.getBytes();
+	byte[] buffer2;
+	if( bufferCount + buffer1.length > buffer.length ) {
+	    buffer2 = new byte[buffer.length + buffer1.length];
+	    System.arraycopy( buffer,0, buffer2, 0, buffer.length );
+	    System.arraycopy( buffer1, 0, buffer2, buffer.length,
buffer1.length );
+	    buffer = buffer2;
+	    bufferCount = bufferCount + buffer1.length;
+	}
+	else {
+	    System.arraycopy( buffer1,0, buffer, bufferCount,
buffer1.length );
+	    bufferCount = bufferCount + buffer1.length;
+	}
   }

[-------------   end of patch   ---------------]



On Sun, 30 Jul 2000, Pilho Kim wrote:

> Hi,
> 
> Is your nightly Tomcat slow, isn't it?
> Or do you meet, sometimes, such errors as
> 
> <---------- error --------------------------------->
> 2000-07-30 11:36:42 - Context: IOException in R( /examples +
> /jsp/snp/snoop.jsp
> + null) - java.net.SocketException: Connection reset by peer: socket write
> error
> 
>         at java.net.SocketOutputStream.socketWrite(Native Method)
>         at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
>         at
> org.apache.tomcat.service.http.HttpResponseAdapter.endHeaders(HttpRes
> ponseAdapter.java:126)
>         at
> org.apache.tomcat.core.BufferedServletOutputStream.sendHeaders(Buffer
> edServletOutputStream.java:126)
>         at
> org.apache.tomcat.core.BufferedServletOutputStream.reallyFlush(Buffer
> edServletOutputStream.java:239)
>         at
> org.apache.tomcat.core.ResponseImpl.finish(ResponseImpl.java:198)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:670
> )
>         at
> org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
> n(HttpConnectionHandler.java:195)
>         at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
> 393)
>         at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java
> :507)
>         at java.lang.Thread.run(Thread.java:484)
> <-------------------------------------------------->
> 
> 
> I hope that the following patch would be nice for Tomcat 3.3.
> I have removed the tow lines
> 
> 	sout.write( buffer, 0, bufferCount );
> 	sout.flush();
> 
> in the method endHeaders() of HttpResponseAdapter.java
> 
> After applying the patch, Tomecat works more faster
> and the above error does not occur.
> 
> Thanks
> 
> Kim, Pilho
> 
>  
> 
> $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/
> service/http/HttpResponseAdapter.java,v 1.12 2000/07/11 03:48:58 alex Exp
> $
> $Revision: 1.12 $
> $Date: 2000/07/11 03:48:58 $
> 
>     public void endHeaders()  throws IOException {
> 	super.endHeaders();
> 	
> 	sendStatus( status, ResponseImpl.getMessage( status ));
> 
> 	int count=headers.size();
> 	for( int i=0; i<count; i++ ) {
> 	    MimeHeaderField field=headers.getField( i );
> 	    // response headers are set by the servlet, so probably we
> have only
> 	    // Strings.
> 	    // XXX date, cookies, etc shoud be extracted from response
> 	    printHead( field.getName() );
> 	    printHead(": ");
> 	    printHead( field.getValue() );
> 	    printHead("\r\n");
> 	}
> 	
> 	printHead( "\r\n" );
> 
> -	sout.write( buffer, 0, bufferCount );
> -	sout.flush();
>     }
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
>