Package org.jboss.netty.handler.ssl
Class SslBufferPool
- java.lang.Object
-
- org.jboss.netty.handler.ssl.SslBufferPool
-
public class SslBufferPool extends java.lang.ObjectAByteBufferpool dedicated forSslHandlerperformance improvement.In most cases, you won't need to create a new pool instance because
SslHandlerhas a default pool instance internally.The reason why
SslHandlerrequires a buffer pool is because the currentSSLEngineimplementation always requires a 17KiB buffer for every 'wrap' and 'unwrap' operation. In most cases, the actual size of the required buffer is much smaller than that, and therefore allocating a 17KiB buffer for every 'wrap' and 'unwrap' operation wastes a lot of memory bandwidth, resulting in the application performance degradation.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallocateDirectprivate static intDEFAULT_POOL_SIZEprivate static intMAX_PACKET_SIZE_ALIGNEDprivate intmaxBufferCountprivate java.util.concurrent.atomic.AtomicIntegernumAllocationsThe number of buffers allocated so far.private java.util.concurrent.BlockingQueue<java.nio.ByteBuffer>poolprivate java.nio.ByteBufferpreallocated
-
Constructor Summary
Constructors Constructor Description SslBufferPool()Creates a new buffer pool whose size is19267584, which can hold1024buffers.SslBufferPool(boolean preallocate, boolean allocateDirect)Creates a new buffer pool whose size is19267584, which can hold1024buffers.SslBufferPool(int maxPoolSize)Creates a new buffer pool.SslBufferPool(int maxPoolSize, boolean preallocate, boolean allocateDirect)Creates a new buffer pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBufferacquireBuffer()Acquire a newByteBufferout of theSslBufferPoolprivate java.nio.ByteBufferallocate(int capacity)intgetMaxPoolSize()Returns the maximum size of this pool in byte unit.intgetUnacquiredPoolSize()Returns the number of bytes which were allocated but have not been acquired yet.voidreleaseBuffer(java.nio.ByteBuffer buffer)Release a previous acquiredByteBuffer
-
-
-
Field Detail
-
MAX_PACKET_SIZE_ALIGNED
private static final int MAX_PACKET_SIZE_ALIGNED
- See Also:
- Constant Field Values
-
DEFAULT_POOL_SIZE
private static final int DEFAULT_POOL_SIZE
- See Also:
- Constant Field Values
-
preallocated
private final java.nio.ByteBuffer preallocated
-
pool
private final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> pool
-
maxBufferCount
private final int maxBufferCount
-
allocateDirect
private final boolean allocateDirect
-
numAllocations
private final java.util.concurrent.atomic.AtomicInteger numAllocations
The number of buffers allocated so far. Used only whenpreallocatedis null.
-
-
Constructor Detail
-
SslBufferPool
public SslBufferPool()
Creates a new buffer pool whose size is19267584, which can hold1024buffers.
-
SslBufferPool
public SslBufferPool(boolean preallocate, boolean allocateDirect)Creates a new buffer pool whose size is19267584, which can hold1024buffers.- Parameters:
preallocate-trueif and only if the buffers in this pool has to be pre-allocated at construction timeallocateDirect-trueif and only if this pool has to allocate direct buffers.
-
SslBufferPool
public SslBufferPool(int maxPoolSize)
Creates a new buffer pool.- Parameters:
maxPoolSize- the maximum number of bytes that this pool can hold
-
SslBufferPool
public SslBufferPool(int maxPoolSize, boolean preallocate, boolean allocateDirect)Creates a new buffer pool.- Parameters:
maxPoolSize- the maximum number of bytes that this pool can holdpreallocate-trueif and only if the buffers in this pool has to be pre-allocated at construction timeallocateDirect-trueif and only if this pool has to allocate direct buffers.
-
-
Method Detail
-
getMaxPoolSize
public int getMaxPoolSize()
Returns the maximum size of this pool in byte unit. The returned value can be somewhat different from what was specified in the constructor.
-
getUnacquiredPoolSize
public int getUnacquiredPoolSize()
Returns the number of bytes which were allocated but have not been acquired yet. You can estimate how optimal the specified maximum pool size is from this value. If it keeps returning0, it means the pool is getting exhausted. If it keeps returns a unnecessarily big value, it means the pool is wasting the heap space.
-
acquireBuffer
public java.nio.ByteBuffer acquireBuffer()
Acquire a newByteBufferout of theSslBufferPool
-
releaseBuffer
public void releaseBuffer(java.nio.ByteBuffer buffer)
Release a previous acquiredByteBuffer
-
allocate
private java.nio.ByteBuffer allocate(int capacity)
-
-