Example usage for io.netty.buffer PooledByteBufAllocator PooledByteBufAllocator

List of usage examples for io.netty.buffer PooledByteBufAllocator PooledByteBufAllocator

Introduction

In this page you can find the example usage for io.netty.buffer PooledByteBufAllocator PooledByteBufAllocator.

Prototype

@Deprecated
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize,
        int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize) 

Source Link

Usage

From source file:com.github.milenkovicm.kafka.util.Allocator.java

License:Apache License

public static PooledByteBufAllocator createPooledByteBufAllocator(boolean allowCache, int numCores) {
    if (numCores == 0) {
        numCores = Runtime.getRuntime().availableProcessors();
    }/*from w  w w .  ja v a2 s.  c o m*/
    return new PooledByteBufAllocator(PlatformDependent.directBufferPreferred(),
            Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores),
            Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"),
                    PlatformDependent.directBufferPreferred() ? 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);
}

From source file:com.github.sparkfy.network.util.NettyUtils.java

License:Apache License

/**
 * 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.
 *//*from w  w  w  . jav  a  2  s  .c o m*/
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);
}

From source file:com.heliosapm.utils.buffer.BufferManager.java

License:Apache License

/**
 * Creates a new BufferManager/*from w  ww .  j av  a  2  s  .  c  o  m*/
 */
private BufferManager() {
    leakDetection = getBoolean(ENABLE_LEAK_DETECTION, DEFAULT_LEAK_DETECTION);
    pooledBuffers = getBoolean("buffers.pooled", true);
    directBuffers = getBoolean("buffers.direct", true);
    nHeapArena = getInt("buffers.heaparenas", DEFAULT_NUM_HEAP_ARENA);
    nDirectArena = getInt("buffers.directarenas", DEFAULT_NUM_DIRECT_ARENA);
    pageSize = getInt("buffers.pagesize", DEFAULT_PAGE_SIZE);
    maxOrder = getInt("buffers.maxorder", DEFAULT_MAX_ORDER);
    tinyCacheSize = getInt("buffers.tcachesize", DEFAULT_TINY_CACHE_SIZE);
    smallCacheSize = getInt("buffers.scachesize", DEFAULT_SMALL_CACHE_SIZE);
    normalCacheSize = getInt("buffers.ncachesize", DEFAULT_NORMAL_CACHE_SIZE);
    pooledBufferAllocator = new PooledByteBufAllocator(directBuffers, nHeapArena, nDirectArena, pageSize,
            maxOrder, tinyCacheSize, smallCacheSize, normalCacheSize);
    unpooledBufferAllocator = new UnpooledByteBufAllocator(directBuffers, leakDetection);
    defaultBufferAllocator = pooledBuffers ? pooledBufferAllocator : unpooledBufferAllocator;
    try {
        objectName = new ObjectName(OBJECT_NAME);
        ManagementFactory.getPlatformMBeanServer().registerMBean(this, objectName);
    } catch (Exception ex) {
        System.err
                .println("Failed to register the BufferManager management interface. Continuing without:" + ex);
    }
    directMonitor = new BufferArenaMonitor(pooledBufferAllocator, true);
    heapMonitor = new BufferArenaMonitor(pooledBufferAllocator, false);
    System.out
            .println("Created BufferManager. Pooled: [" + pooledBuffers + "], Direct:[" + directBuffers + "]");
}

From source file:com.vmware.dcp.common.http.netty.NettyChannelContext.java

License:Open Source License

static PooledByteBufAllocator createAllocator() {
    // We are using defaults from the code internals since the pooled allocator does not
    // expose the values it calculates. The available constructor methods that take cache
    // sizes require us to pass things like max order and page size.
    // maxOrder determines the allocation chunk size as a multiple of page size
    int maxOrder = 4;
    return new PooledByteBufAllocator(true, 2, 2, 8192, maxOrder, 64, 32, 16);
}

From source file:com.yahoo.pulsar.broker.stats.BookieClientsStatsGeneratorTest.java

License:Apache License

@Test
public void testJvmDirectMemoryUsedMetric() throws Exception {
    PooledByteBufAllocator allocator = new PooledByteBufAllocator( //
            true, // preferDirect
            0, // nHeapArenas,
            1, // nDirectArena
            8192, // pageSize
            11, // maxOrder
            64, // tinyCacheSize
            32, // smallCacheSize
            8 // normalCacheSize
    );//from www .j ava2 s  .co  m
    int allocateMemory = 17777216;
    long directMemory1 = JvmMetrics.getJvmDirectMemoryUsed();
    ByteBuf buf2 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1 + allocateMemory);
    ByteBuf buf3 = allocator.directBuffer(allocateMemory, allocateMemory);
    long directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2 + allocateMemory);
    buf3.release();
    directMemory3 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory3, directMemory2);
    buf2.release();
    directMemory2 = JvmMetrics.getJvmDirectMemoryUsed();
    assertEquals(directMemory2, directMemory1);

}