Hi Daniel,
On 08.12.14 09:32, Daniel Feist wrote:
> I see there is a system property I can use to limit maximum size of
> these direct bufffers and thus avoid the OutOfMemoryExceptions, but
> I'm wondering why the MemoryManager is explicitlu being bypassed here
> rather than simply being used? This also means there are two
> allocations and reads per request and not just one. Can anyone shed
> some light?
Well, if you pass HeapByteBuffer to a SocketChannel - it'll do the same
underneath - allocate (or take pooled) direct ByteBuffer and use it for
reading.
So we basically do the same in our code and passing direct ByteBuffer to
a SocketChannel, so SocketChannel itself will not allocate direct
ByteBuffer.
This approach gives us one advantage - once we read to the direct
ByteBuffer - we know the exact amount of bytes we need to allocate from
the MemoryManager (no guessing).
Hope it will help.
WBR,
Alexey.
PS: Pls. give a shot to PooledMemoryManager, it can work with direct and
heap buffers and it performed well on our tests.