Maximum buffer size with PooledByteBufAllocator

2,044 views
Skip to first unread message

Mark Anderson

unread,
Jul 1, 2014, 7:55:26 AM7/1/14
to ne...@googlegroups.com
While answering a previous question (https://groups.google.com/forum/#!topic/netty/97k_NbMsZkw) Norman mentioned that the default PooledByteBufAllocator configuration will not pool buffers with a size of 350k.

With the default configuration the type of ByteBuf returned by PooledByteBufAllocator is PooledUnsafeDirectByteBuf. Does this mean that the buffer returned is actually pooled?

In PooledByteBufAllocator I noticed the system property io.netty.allocator.maxCachedBufferCapacity with a default value of 32k. Is this the default max size of a pooled ByteBuf?

Could you please clarify the default behaviour of PooledButeBufAllocator in relation to allocating buffers of size 350k - 500k. What system properties do I need to set to achieve this?

Thanks,
Mark

이희승 (Trustin Lee)

unread,
Jul 1, 2014, 7:52:28 PM7/1/14
to Netty Discussions
Hi Mark,

PooledByteBufAllocator will pool the buffers up to the configured chunk size, whose default is 16 MiB.  You can override this value by specifying two parameters: pageSize and maxOrder.

The default values of them are 8192 and 11 respectively.  Chunk size is pageSize << maxOrder.  You can of course adjust these parameters by either specifying system properties to override the default or by specifying constructor parameters.  For more information, please check the source code of PooledByteBufAllocator [1], or enable DEBUG-level logging for io.netty.*:

    http://netty.io/4.0/xref/io/netty/buffer/PooledByteBufAllocator.html

Regardless if thread-local cache is enabled or not, the buffers up to chunkSize will be pooled.

Another thing to note is that even if you allocated a buffer that's larger than chunkSize, the type of the buffer returned by the allocator will be Pooled*ByteBuf.

HTH,
T



--

---
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

이희승 (Trustin Lee)

unread,
Jul 1, 2014, 7:53:53 PM7/1/14
to Netty Discussions
The reason why the allocator returns Pooled*ByteBuf even for an unpooled buffer is that a user can reduce the capacity of the buffer later, turning the buffer into a pooled one.

Mark Anderson

unread,
Jul 2, 2014, 3:22:14 AM7/2/14
to ne...@googlegroups.com
Thanks Trustin. That confirms that I don't need to change any of the default settings to pool the buffer sizes I am working with.

Mark
Reply all
Reply to author
Forward
0 new messages