fixed SSL buffer pool

This commit is contained in:
Greg Wilkins 2011-11-09 17:39:59 +11:00
parent a36342438c
commit af4c40d793
3 changed files with 46 additions and 39 deletions

View File

@ -51,13 +51,13 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
private static final NIOBuffer __ZERO_BUFFER=new IndirectNIOBuffer(0); private static final NIOBuffer __ZERO_BUFFER=new IndirectNIOBuffer(0);
private final ThreadLocal<NIOBuffer> __inBuffer = new ThreadLocal<NIOBuffer>(); private static final ThreadLocal<SslBuffers> __buffers = new ThreadLocal<SslBuffers>();
private final ThreadLocal<NIOBuffer> __outBuffer = new ThreadLocal<NIOBuffer>();
private final SSLEngine _engine; private final SSLEngine _engine;
private final SSLSession _session; private final SSLSession _session;
private AsyncConnection _connection; private AsyncConnection _connection;
private final SslEndPoint _sslEndPoint = new SslEndPoint(); private final SslEndPoint _sslEndPoint = new SslEndPoint();
private int _allocations; private int _allocations;
private SslBuffers _buffers;
private NIOBuffer _inbound; private NIOBuffer _inbound;
private NIOBuffer _unwrapBuf; private NIOBuffer _unwrapBuf;
private NIOBuffer _outbound; private NIOBuffer _outbound;
@ -66,6 +66,23 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
private boolean _handshook; private boolean _handshook;
private boolean _oshut; private boolean _oshut;
/* ------------------------------------------------------------ */
/* this is a half baked buffer pool
*/
private static class SslBuffers
{
final NIOBuffer _in;
final NIOBuffer _out;
final NIOBuffer _unwrap;
SslBuffers(int packetSize, int appSize)
{
System.err.println("New "+Thread.currentThread());
_in=new IndirectNIOBuffer(packetSize);
_out=new IndirectNIOBuffer(packetSize);
_unwrap=new IndirectNIOBuffer(appSize);
}
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public SslConnection(SSLEngine engine,EndPoint endp) public SslConnection(SSLEngine engine,EndPoint endp)
@ -118,53 +135,51 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
{ {
_allowRenegotiate = allowRenegotiate; _allowRenegotiate = allowRenegotiate;
} }
/* ------------------------------------------------------------ */
private void allocateBuffers() private void allocateBuffers()
{ {
synchronized (this) synchronized (this)
{ {
if (_allocations++==0) if (_allocations++==0)
{ {
if (_inbound==null) if (_buffers==null)
{ {
_inbound = __inBuffer.get(); _buffers=__buffers.get();
if (_inbound==null) if (_buffers==null)
_inbound=new IndirectNIOBuffer(_session.getPacketBufferSize()*2); _buffers=new SslBuffers(_session.getPacketBufferSize()*2,_session.getApplicationBufferSize()*2);
} _inbound=_buffers._in;
_outbound=_buffers._out;
if (_outbound==null) _unwrapBuf=_buffers._unwrap;
{ __buffers.set(null);
_outbound = __outBuffer.get();
if (_outbound==null)
_outbound=new IndirectNIOBuffer(_session.getPacketBufferSize()*2);
} }
} }
} }
} }
/* ------------------------------------------------------------ */
private void releaseBuffers() private void releaseBuffers()
{ {
synchronized (this) synchronized (this)
{ {
if (--_allocations==0) if (--_allocations==0)
{ {
if (_inbound!=null && _inbound.length()==0) if (_buffers!=null &&
_inbound.length()==0 &&
_outbound.length()==0 &&
_unwrapBuf.length()==0)
{ {
__inBuffer.set(_inbound);
_inbound=null; _inbound=null;
}
if (_outbound!=null && _outbound.length()==0)
{
__outBuffer.set(_outbound);
_outbound=null; _outbound=null;
}
if (_unwrapBuf!=null && _unwrapBuf.length()==0)
_unwrapBuf=null; _unwrapBuf=null;
__buffers.set(_buffers);
_buffers=null;
}
} }
} }
} }
/* ------------------------------------------------------------ */
public Connection handle() throws IOException public Connection handle() throws IOException
{ {
try try
@ -202,21 +217,25 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
return this; return this;
} }
/* ------------------------------------------------------------ */
public boolean isIdle() public boolean isIdle()
{ {
return false; return false;
} }
/* ------------------------------------------------------------ */
public boolean isSuspended() public boolean isSuspended()
{ {
return false; return false;
} }
/* ------------------------------------------------------------ */
public void onClose() public void onClose()
{ {
} }
/* ------------------------------------------------------------ */
public void onInputShutdown() throws IOException public void onInputShutdown() throws IOException
{ {
@ -226,11 +245,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException private synchronized boolean process(Buffer toFill, Buffer toFlush) throws IOException
{ {
if (toFill==null) if (toFill==null)
{
if (_unwrapBuf==null)
_unwrapBuf=new IndirectNIOBuffer(_session.getApplicationBufferSize()*2);
toFill=_unwrapBuf; toFill=_unwrapBuf;
}
else if (toFill.capacity()<_session.getApplicationBufferSize()) else if (toFill.capacity()<_session.getApplicationBufferSize())
{ {
boolean progress=process(null,toFlush); boolean progress=process(null,toFlush);

View File

@ -507,15 +507,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
buf.append("Async"); buf.append("Async");
long responseLength = response.getContentCount(); long responseLength = response.getContentCount();
if (responseLength == 0) if (responseLength >= 0)
{
System.err.println("Content-Length: "+response.getHeader("Content-Length")+" "+request.getConnection()+" "+request.getConnection().getEndPoint());
new Throwable().printStackTrace();
System.exit(1);
buf.append(' ');
buf.append('0');
}
else if (responseLength >= 0)
{ {
buf.append(' '); buf.append(' ');
if (responseLength > 99999) if (responseLength > 99999)

View File

@ -36,7 +36,7 @@
<filter-class>org.eclipse.jetty.servlets.QoSFilter</filter-class> <filter-class>org.eclipse.jetty.servlets.QoSFilter</filter-class>
<init-param> <init-param>
<param-name>maxRequests</param-name> <param-name>maxRequests</param-name>
<param-value>20</param-value> <param-value>10000</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>managedAttr</param-name> <param-name>managedAttr</param-name>