jetty-9 use spare space in content buffer for header

This commit is contained in:
Greg Wilkins 2012-12-14 08:30:46 +11:00
parent e5679d42c0
commit 5b8a9bb95e
2 changed files with 14 additions and 8 deletions

View File

@ -49,6 +49,9 @@ import org.eclipse.jetty.util.log.Logger;
public class HttpConnection extends AbstractConnection implements Runnable, HttpTransport
{
public static final String UPGRADE_CONNECTION_ATTRIBUTE = "org.eclipse.jetty.server.HttpConnection.UPGRADE";
private static final boolean REQUEST_BUFFER_DIRECT=false;
private static final boolean HEADER_BUFFER_DIRECT=false;
private static final boolean CHUNK_BUFFER_DIRECT=false;
private static final Logger LOG = Log.getLogger(HttpConnection.class);
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<>();
@ -226,7 +229,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
if (!call_channel && BufferUtil.isEmpty(_requestBuffer))
{
if (_requestBuffer == null)
_requestBuffer = _bufferPool.acquire(getInputBufferSize(), false);
_requestBuffer = _bufferPool.acquire(getInputBufferSize(), REQUEST_BUFFER_DIRECT);
int filled = getEndPoint().fill(_requestBuffer);
if (filled==0) // Do a retry on fill 0 (optimisation for SSL connections)
@ -359,14 +362,14 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
content.limit(l);
}
else
header = _bufferPool.acquire(_config.getResponseHeaderSize(), false);
header = _bufferPool.acquire(_config.getResponseHeaderSize(), HEADER_BUFFER_DIRECT);
continue;
}
case NEED_CHUNK:
{
chunk = _chunk;
if (chunk==null)
chunk = _chunk = _bufferPool.acquire(HttpGenerator.CHUNK_SIZE, false);
chunk = _chunk = _bufferPool.acquire(HttpGenerator.CHUNK_SIZE, CHUNK_BUFFER_DIRECT);
continue;
}
case FLUSH:
@ -586,7 +589,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
int size=getInputBufferSize();
if (size<content_length)
size=size*4; // TODO tune this
_requestBuffer=_bufferPool.acquire(size,false);
_requestBuffer=_bufferPool.acquire(size,REQUEST_BUFFER_DIRECT);
}
// read some data

View File

@ -49,6 +49,9 @@ import org.eclipse.jetty.util.resource.Resource;
*/
public class HttpOutput extends ServletOutputStream
{
private static final boolean OUTPUT_BUFFER_DIRECT=false;
private static final boolean CHANNEL_BUFFER_DIRECT=true;
private static final boolean STREAM_BUFFER_DIRECT=false;
private static Logger LOG = Log.getLogger(HttpOutput.class);
private final HttpChannel<?> _channel;
private boolean _closed;
@ -165,7 +168,7 @@ public class HttpOutput extends ServletOutputStream
}
// Allocate an aggregate buffer
_aggregate = _channel.getByteBufferPool().acquire(size, false);
_aggregate = _channel.getByteBufferPool().acquire(size, OUTPUT_BUFFER_DIRECT);
}
// Do we have space to aggregate ?
@ -206,7 +209,7 @@ public class HttpOutput extends ServletOutputStream
throw new EOFException();
if (_aggregate == null)
_aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), false);
_aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), OUTPUT_BUFFER_DIRECT);
BufferUtil.append(_aggregate, (byte)b);
_written++;
@ -278,7 +281,7 @@ public class HttpOutput extends ServletOutputStream
else if (content instanceof ReadableByteChannel)
{
ReadableByteChannel channel = (ReadableByteChannel)content;
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), true);
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), CHANNEL_BUFFER_DIRECT);
try
{
while(channel.isOpen())
@ -300,7 +303,7 @@ public class HttpOutput extends ServletOutputStream
else if (content instanceof InputStream)
{
InputStream in = (InputStream)content;
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), false);
ByteBuffer buffer = _channel.getByteBufferPool().acquire(getBufferSize(), STREAM_BUFFER_DIRECT);
byte[] array = buffer.array();
int offset=buffer.arrayOffset();
int size=array.length-offset;