public class SslBufferPool
extends java.lang.Object
ByteBuffer pool dedicated for SslHandler performance improvement.
In most cases, you won't need to create a new pool instance because SslHandler has a default pool
instance internally.
The reason why SslHandler requires a buffer pool is because the current SSLEngine implementation
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.
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allocateDirect |
private static int |
DEFAULT_POOL_SIZE |
private static int |
MAX_PACKET_SIZE_ALIGNED |
private int |
maxBufferCount |
private java.util.concurrent.atomic.AtomicInteger |
numAllocations
The number of buffers allocated so far.
|
private java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> |
pool |
private java.nio.ByteBuffer |
preallocated |
| Constructor and Description |
|---|
SslBufferPool()
Creates a new buffer pool whose size is
19267584, which can hold 1024 buffers. |
SslBufferPool(boolean preallocate,
boolean allocateDirect)
Creates a new buffer pool whose size is
19267584, which can hold 1024 buffers. |
SslBufferPool(int maxPoolSize)
Creates a new buffer pool.
|
SslBufferPool(int maxPoolSize,
boolean preallocate,
boolean allocateDirect)
Creates a new buffer pool.
|
| Modifier and Type | Method and Description |
|---|---|
java.nio.ByteBuffer |
acquireBuffer()
Acquire a new
ByteBuffer out of the SslBufferPool |
private java.nio.ByteBuffer |
allocate(int capacity) |
int |
getMaxPoolSize()
Returns the maximum size of this pool in byte unit.
|
int |
getUnacquiredPoolSize()
Returns the number of bytes which were allocated but have not been
acquired yet.
|
void |
releaseBuffer(java.nio.ByteBuffer buffer)
Release a previous acquired
ByteBuffer |
private static final int MAX_PACKET_SIZE_ALIGNED
private static final int DEFAULT_POOL_SIZE
private final java.nio.ByteBuffer preallocated
private final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> pool
private final int maxBufferCount
private final boolean allocateDirect
private final java.util.concurrent.atomic.AtomicInteger numAllocations
preallocated is null.public SslBufferPool()
19267584, which can hold 1024 buffers.public SslBufferPool(boolean preallocate,
boolean allocateDirect)
19267584, which can hold 1024 buffers.preallocate - true if and only if the buffers in this pool has to be pre-allocated
at construction timeallocateDirect - true if and only if this pool has to allocate direct buffers.public SslBufferPool(int maxPoolSize)
maxPoolSize - the maximum number of bytes that this pool can holdpublic SslBufferPool(int maxPoolSize,
boolean preallocate,
boolean allocateDirect)
maxPoolSize - the maximum number of bytes that this pool can holdpreallocate - true if and only if the buffers in this pool has to be pre-allocated
at construction timeallocateDirect - true if and only if this pool has to allocate direct buffers.public int getMaxPoolSize()
public int getUnacquiredPoolSize()
0, it means the
pool is getting exhausted. If it keeps returns a unnecessarily big
value, it means the pool is wasting the heap space.public java.nio.ByteBuffer acquireBuffer()
ByteBuffer out of the SslBufferPoolpublic void releaseBuffer(java.nio.ByteBuffer buffer)
ByteBufferprivate java.nio.ByteBuffer allocate(int capacity)