Author: fhanik
Date: Thu Oct 26 08:24:24 2006
New Revision: 468035
URL: http://svn.apache.org/viewvc?view=rev&rev=468035
Log:
Reverted the removal of the "socket buffer", writing to a ByteBuffer is
extremely slow, so it should only be done in chunks
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?view=diff&rev=468035&r1=468034&r2=468035
==============================================================================
---
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
(original)
+++
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
Thu Oct 26 08:24:24 2006
@@ -69,8 +69,15 @@
this.response = response;
headers = response.getMimeHeaders();
- //buf = new byte[headerBufferSize];
+ buf = new byte[headerBufferSize];
+ if (headerBufferSize < (8 * 1024)) {
+ bbufLimit = 6 * 1500;
+ } else {
+ bbufLimit = (headerBufferSize / 1500 + 1) * 1500;
+ }
+ //bbuf = ByteBuffer.allocateDirect(bbufLimit);
+
outputStreamOutputBuffer = new SocketOutputBuffer();
filterLibrary = new OutputFilter[0];
@@ -128,7 +135,7 @@
/**
* Pointer to the current write buffer.
*/
- //protected byte[] buf;
+ protected byte[] buf;
/**
@@ -440,12 +447,11 @@
/**
* Send the response status line.
*/
- public void sendStatus() throws IOException {
+ public void sendStatus() {
// Write protocol name
write(Constants.HTTP_11_BYTES);
- addToBB(Constants.SP);
- pos++;
+ buf[pos++] = Constants.SP;
// Write status code
int status = response.getStatus();
@@ -463,8 +469,7 @@
write(status);
}
- addToBB(Constants.SP);
- pos++;
+ buf[pos++] = Constants.SP;
// Write message
String message = response.getMessage();
@@ -475,10 +480,8 @@
}
// End the response status line
- addToBB(Constants.CR);
- pos++;
- addToBB(Constants.LF);
- pos++;
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -489,18 +492,14 @@
* @param name Header name
* @param value Header value
*/
- public void sendHeader(MessageBytes name, MessageBytes value) throws
IOException {
+ public void sendHeader(MessageBytes name, MessageBytes value) {
write(name);
- addToBB(Constants.COLON);
- pos++;
- addToBB(Constants.SP);
- pos++;
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- addToBB(Constants.CR);
- pos++;
- addToBB(Constants.LF);
- pos++;
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -511,18 +510,15 @@
* @param name Header name
* @param value Header value
*/
- public void sendHeader(ByteChunk name, ByteChunk value) throws IOException
{
+ public void sendHeader(ByteChunk name, ByteChunk value) {
write(name);
- addToBB(Constants.COLON);
- pos++;
- addToBB(Constants.SP);
- pos++;
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- addToBB(Constants.CR);
- pos++;
- addToBB(Constants.LF);
- pos++;
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
+
}
@@ -535,16 +531,11 @@
public void sendHeader(String name, String value) {
write(name);
- addToBB(Constants.COLON);
- pos++;
- addToBB(Constants.SP);
- pos++;
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- addToBB(Constants.CR);
- pos++;
- addToBB(Constants.LF);
- pos++;
-
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -554,10 +545,8 @@
*/
public void endHeaders() {
- addToBB(Constants.CR);
- pos++;
- addToBB(Constants.LF);
- pos++;
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -609,28 +598,17 @@
if (pos > 0) {
// Sending the response header buffer
- //flushBuffer();//do we need this?
+ addToBB(buf, 0, pos);
}
}
int total = 0;
- private void addToBB(byte b) {
- ByteBuffer bytebuffer = socket.getBufHandler().getWriteBuffer();
- final int length = 1;
- if (bytebuffer.remaining() <= length) {
- try { flushBuffer();} catch (IOException x) {throw new
RuntimeException(x);}
- }
- bytebuffer.put(b);
- total += length;
- }
-
private void addToBB(byte[] buf, int offset, int length) throws
IOException {
- ByteBuffer bytebuffer = socket.getBufHandler().getWriteBuffer();
- if (bytebuffer.remaining() <= length) {
+ if (socket.getBufHandler().getWriteBuffer().remaining() <= length) {
flushBuffer();
}
- bytebuffer.put(buf, offset, length);
+ socket.getBufHandler().getWriteBuffer().put(buf, offset, length);
total += length;
}
@@ -642,7 +620,7 @@
*
* @param mb data to be written
*/
- protected void write(MessageBytes mb) throws IOException {
+ protected void write(MessageBytes mb) {
if (mb.getType() == MessageBytes.T_BYTES) {
ByteChunk bc = mb.getByteChunk();
@@ -664,10 +642,11 @@
*
* @param bc data to be written
*/
- protected void write(ByteChunk bc) throws IOException{
+ protected void write(ByteChunk bc) {
// Writing the byte chunk to the output buffer
- addToBB(bc.getBytes(), bc.getStart(),bc.getLength());
+ System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos,
+ bc.getLength());
pos = pos + bc.getLength();
}
@@ -696,8 +675,7 @@
} else if (c == 127) {
c = ' ';
}
- addToBB((byte) c);
- pos++;
+ buf[pos++] = (byte) c;
}
}
@@ -710,10 +688,10 @@
*
* @param b data to be written
*/
- public void write(byte[] b) throws IOException {
+ public void write(byte[] b) {
// Writing the byte chunk to the output buffer
- addToBB(b,0,b.length);
+ System.arraycopy(b, 0, buf, pos, b.length);
pos = pos + b.length;
}
@@ -744,8 +722,7 @@
} else if (c == 127) {
c = ' ';
}
- addToBB((byte) c);
- pos++;
+ buf[pos++] = (byte) c;
}
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=468035&r1=468034&r2=468035
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu
Oct 26 08:24:24 2006
@@ -170,7 +170,10 @@
Selector sel = pol!=null?pol.getSelector():null;
SelectionKey key =
sel!=null?socket.getIOChannel().keyFor(sel):null;
KeyAttachment att = key!=null?(KeyAttachment)key.attachment():null;
- if ( att!=null ) { att.reset(); keyCache.offer(att); }
+ if ( att!=null ) {
+ att.reset();
+ keyCache.offer(att);
+ }
if ( key!=null ) key.attach(null);
boolean offer =
socketProperties.getBufferPool()==-1?true:size.get()<socketProperties.getBufferPool();
offer = offer &&
(socketProperties.getBufferPoolSize()==-1?true:(bytes.get()+socket.getBufferSize())<socketProperties.getBufferPoolSize());
@@ -217,7 +220,7 @@
/**
* Maximum amount of worker threads.
*/
- protected int maxThreads = 40;
+ protected int maxThreads = 400;
public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; }
public int getMaxThreads() { return maxThreads; }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]