| An
IoBufferAllocator that caches the buffers which are likely to
be reused during auto-expansion of the buffers.
In
SimpleBufferAllocator , the underlying
ByteBuffer of
the
IoBuffer is reallocated on its capacity change, which means
the newly allocated bigger
ByteBuffer replaces the old small
ByteBuffer . Consequently, the old
ByteBuffer is marked
for garbage collection.
It's not a problem in most cases as long as the capacity change doesn't
happen frequently. However, once it happens too often, it burdens the
VM and the cost of filling the newly allocated
ByteBuffer with
NUL surpass the cost of accessing the cache. In 2 dual-core
Opteron Italy 270 processors,
CachedBufferAllocator outperformed
SimpleBufferAllocator in the following situation:
- when a 32 bytes buffer is expanded 4 or more times,
- when a 64 bytes buffer is expanded 4 or more times,
- when a 128 bytes buffer is expanded 2 or more times,
- and when a 256 bytes or bigger buffer is expanded 1 or more times.
Please note the observation above is subject to change in a different
environment.
CachedBufferAllocator uses
ThreadLocal to store the cached
buffer, allocates buffers whose capacity is power of 2 only and provides
performance advantage if
IoBuffer.free is called properly.
author: The Apache MINA Project (dev@mina.apache.org) version: $Rev: 594400 $, $Date: 2007-11-12 19:49:43 -0700 (Mon, 12 Nov 2007) $ |