/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
/** * Default prefer direct - System Property: io.netty.noPreferDirect - default false */ public static boolean defaultPreferDirect() { return PlatformDependent.directBufferPreferred(); }
protected void init(){ ThreadFactory bossFactory = new DefaultThreadFactory("netty.acceptor.boss"); ThreadFactory workerFactory = new DefaultThreadFactory("netty.acceptor.worker"); boss = initEventLoopGroup(1, bossFactory); worker = initEventLoopGroup(nWorkers, workerFactory); //使用池化的directBuffer /** * 一般高性能的场景下,使用的堆外内存,也就是直接内存,使用堆外内存的好处就是减少内存的拷贝,和上下文的切换,缺点是 * 堆外内存处理的不好容易发生堆外内存OOM * 当然也要看当前的JVM是否只是使用堆外内存,换而言之就是是否能够获取到Unsafe对象#PlatformDependent.directBufferPreferred() */ allocator = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred()); //create && group bootstrap= new ServerBootstrap().group(worker, worker); //ByteBufAllocator 配置 bootstrap.childOption(ChannelOption.ALLOCATOR, allocator); }
allocator = new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());
/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * borrowed from Spark */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(PooledByteBufAllocator.defaultNumHeapArena(), numCores), Math.min(PooledByteBufAllocator.defaultNumDirectArena(), allowDirectBufs ? numCores : 0), PooledByteBufAllocator.defaultPageSize(), PooledByteBufAllocator.defaultMaxOrder(), allowCache ? PooledByteBufAllocator.defaultTinyCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultSmallCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultNormalCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultUseCacheForAllThreads() : false ); } }
/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(PooledByteBufAllocator.defaultNumHeapArena(), numCores), Math.min(PooledByteBufAllocator.defaultNumDirectArena(), allowDirectBufs ? numCores : 0), PooledByteBufAllocator.defaultPageSize(), PooledByteBufAllocator.defaultMaxOrder(), allowCache ? PooledByteBufAllocator.defaultTinyCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultSmallCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultNormalCacheSize() : 0, allowCache ? PooledByteBufAllocator.defaultUseCacheForAllThreads() : false ); } }