Author: remm Date: Thu Nov 16 03:17:41 2006 New Revision: 475686 URL: http://svn.apache.org/viewvc?view=rev&rev=475686 Log: - Port memory optimizations to the classic HTTP connector.
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java?view=diff&rev=475686&r1=475685&r2=475686 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java Thu Nov 16 03:17:41 2006 @@ -61,13 +61,7 @@ this.request = request; headers = request.getMimeHeaders(); - headerBuffer1 = new byte[headerBufferSize]; - headerBuffer2 = new byte[headerBufferSize]; - bodyBuffer = new byte[headerBufferSize]; - buf = headerBuffer1; - - headerBuffer = new char[headerBufferSize]; - ascbuf = headerBuffer; + buf = new byte[headerBufferSize]; inputStreamInputBuffer = new InputStreamInputBuffer(); @@ -125,12 +119,6 @@ /** - * Pointer to the US-ASCII header buffer. - */ - protected char[] ascbuf; - - - /** * Last valid byte. */ protected int lastValid; @@ -143,27 +131,10 @@ /** - * HTTP header buffer no 1. - */ - protected byte[] headerBuffer1; - - - /** - * HTTP header buffer no 2. - */ - protected byte[] headerBuffer2; - - - /** - * HTTP body buffer. - */ - protected byte[] bodyBuffer; - - - /** - * US-ASCII header buffer. + * Pos of the end of the header in the buffer, which is also the + * start of the body. */ - protected char[] headerBuffer; + protected int end; /** @@ -306,7 +277,6 @@ request.recycle(); inputStream = null; - buf = headerBuffer1; lastValid = 0; pos = 0; lastActiveFilter = -1; @@ -322,26 +292,23 @@ * consumed. This method only resets all the pointers so that we are ready * to parse the next HTTP request. */ - public void nextRequest() - throws IOException { + public void nextRequest() { // Recycle Request object request.recycle(); - // Determine the header buffer used for next request - byte[] newHeaderBuf = null; - if (buf == headerBuffer1) { - newHeaderBuf = headerBuffer2; - } else { - newHeaderBuf = headerBuffer1; + // Copy leftover bytes to the beginning of the buffer + if (lastValid - pos > 0) { + int npos = 0; + int opos = pos; + while (lastValid - opos > opos - npos) { + System.arraycopy(buf, opos, buf, npos, opos - npos); + npos += pos; + opos += pos; + } + System.arraycopy(buf, opos, buf, npos, lastValid - opos); } - // Copy leftover bytes from buf to newHeaderBuf - System.arraycopy(buf, pos, newHeaderBuf, 0, lastValid - pos); - - // Swap buffers - buf = newHeaderBuf; - // Recycle filters for (int i = 0; i <= lastActiveFilter; i++) { activeFilters[i].recycle(); @@ -424,11 +391,9 @@ throw new EOFException(sm.getString("iib.eof.error")); } - ascbuf[pos] = (char) buf[pos]; - if (buf[pos] == Constants.SP) { space = true; - request.method().setChars(ascbuf, start, pos - start); + request.method().setBytes(buf, start, pos - start); } pos++; @@ -499,8 +464,6 @@ throw new EOFException(sm.getString("iib.eof.error")); } - ascbuf[pos] = (char) buf[pos]; - if (buf[pos] == Constants.CR) { end = pos; } else if (buf[pos] == Constants.LF) { @@ -514,7 +477,7 @@ } if ((end - start) > 0) { - request.protocol().setChars(ascbuf, start, end - start); + request.protocol().setBytes(buf, start, end - start); } else { request.protocol().setString(""); } @@ -532,6 +495,7 @@ } parsingHeader = false; + end = pos; } @@ -594,15 +558,13 @@ if (buf[pos] == Constants.COLON) { colon = true; - headerValue = headers.addValue(ascbuf, start, pos - start); + headerValue = headers.addValue(buf, start, pos - start); } chr = buf[pos]; if ((chr >= Constants.A) && (chr <= Constants.Z)) { buf[pos] = (byte) (chr - Constants.LC_OFFSET); } - ascbuf[pos] = (char) buf[pos]; - pos++; } @@ -742,12 +704,18 @@ } else { - buf = bodyBuffer; - pos = 0; - lastValid = 0; - nRead = inputStream.read(buf, 0, buf.length); + if (buf.length - end < 4500) { + // In this case, the request header was really large, so we allocate a + // brand new one; the old one will get GCed when subsequent requests + // clear all references + buf = new byte[buf.length]; + end = 0; + } + pos = end; + lastValid = pos; + nRead = inputStream.read(buf, pos, buf.length - lastValid); if (nRead > 0) { - lastValid = nRead; + lastValid = pos + nRead; } } Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java?view=diff&rev=475686&r1=475685&r2=475686 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java Thu Nov 16 03:17:41 2006 @@ -64,8 +64,7 @@ headers = response.getMimeHeaders(); - headerBuffer = new byte[headerBufferSize]; - buf = headerBuffer; + buf = new byte[headerBufferSize]; outputStreamOutputBuffer = new OutputStreamOutputBuffer(); @@ -120,7 +119,7 @@ /** - * Pointer to the current read buffer. + * The buffer used for header composition. */ protected byte[] buf; @@ -132,12 +131,6 @@ /** - * HTTP header buffer. - */ - protected byte[] headerBuffer; - - - /** * Underlying output stream. */ protected OutputStream outputStream; @@ -336,7 +329,6 @@ socketBuffer.recycle(); outputStream = null; - buf = headerBuffer; pos = 0; lastActiveFilter = -1; committed = false; @@ -356,9 +348,6 @@ // Recycle Request object response.recycle(); socketBuffer.recycle(); - - // Determine the header buffer used for next request - buf = headerBuffer; // Recycle filters for (int i = 0; i <= lastActiveFilter; i++) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]