[#3888] Use 2 * cores as default minimum for pool arenas.

Motivation:

At the moment we use 1 * cores as default mimimum for pool arenas. This can easily lead to conditions as we use 2 * cores as default for EventLoop's when using NIO or EPOLL. If we choose a smaller number we will run into hotspots as allocation and deallocation needs to be synchronized on the PoolArena.

Modifications:

Change the default number of arenas to 2 * cores.

Result:

Less conditions when using the default settings.
This commit is contained in:
Norman Maurer 2015-06-17 09:39:54 +02:00
parent 303cb53523
commit 1796cfc419

View File

@ -69,18 +69,24 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator {
// Determine reasonable default for nHeapArena and nDirectArena. // Determine reasonable default for nHeapArena and nDirectArena.
// Assuming each arena has 3 chunks, the pool should not consume more than 50% of max memory. // Assuming each arena has 3 chunks, the pool should not consume more than 50% of max memory.
final Runtime runtime = Runtime.getRuntime(); final Runtime runtime = Runtime.getRuntime();
// Use 2 * cores by default to reduce condition as we use 2 * cores for the number of EventLoops
// in NIO and EPOLL as well. If we choose a smaller number we will run into hotspots as allocation and
// deallocation needs to be synchronized on the PoolArena.
// See https://github.com/netty/netty/issues/3888
final int defaultMinNumArena = runtime.availableProcessors() * 2;
final int defaultChunkSize = DEFAULT_PAGE_SIZE << DEFAULT_MAX_ORDER; final int defaultChunkSize = DEFAULT_PAGE_SIZE << DEFAULT_MAX_ORDER;
DEFAULT_NUM_HEAP_ARENA = Math.max(0, DEFAULT_NUM_HEAP_ARENA = Math.max(0,
SystemPropertyUtil.getInt( SystemPropertyUtil.getInt(
"io.netty.allocator.numHeapArenas", "io.netty.allocator.numHeapArenas",
(int) Math.min( (int) Math.min(
runtime.availableProcessors(), defaultMinNumArena,
Runtime.getRuntime().maxMemory() / defaultChunkSize / 2 / 3))); runtime.maxMemory() / defaultChunkSize / 2 / 3)));
DEFAULT_NUM_DIRECT_ARENA = Math.max(0, DEFAULT_NUM_DIRECT_ARENA = Math.max(0,
SystemPropertyUtil.getInt( SystemPropertyUtil.getInt(
"io.netty.allocator.numDirectArenas", "io.netty.allocator.numDirectArenas",
(int) Math.min( (int) Math.min(
runtime.availableProcessors(), defaultMinNumArena,
PlatformDependent.maxDirectMemory() / defaultChunkSize / 2 / 3))); PlatformDependent.maxDirectMemory() / defaultChunkSize / 2 / 3)));
// cache sizes // cache sizes
@ -202,7 +208,7 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator {
int tinyCacheSize, int smallCacheSize, int normalCacheSize, int tinyCacheSize, int smallCacheSize, int normalCacheSize,
long cacheThreadAliveCheckInterval) { long cacheThreadAliveCheckInterval) {
this(preferDirect, nHeapArena, nDirectArena, pageSize, maxOrder, this(preferDirect, nHeapArena, nDirectArena, pageSize, maxOrder,
tinyCacheSize, smallCacheSize, normalCacheSize); tinyCacheSize, smallCacheSize, normalCacheSize);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")