Example usage for io.netty.buffer PooledByteBufAllocator defaultMaxOrder

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

Introduction

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

Prototype

public static int defaultMaxOrder() 

Source Link

Document

Default maximum order - System Property: io.netty.allocator.maxOrder - default 11

Usage

From source file:org.apache.bookkeeper.common.allocator.impl.ByteBufAllocatorImpl.java

License:Apache License

ByteBufAllocatorImpl(ByteBufAllocator pooledAllocator, ByteBufAllocator unpooledAllocator,
        PoolingPolicy poolingPolicy, int poolingConcurrency, OutOfMemoryPolicy outOfMemoryPolicy,
        Consumer<OutOfMemoryError> outOfMemoryListener, LeakDetectionPolicy leakDetectionPolicy) {
    super(poolingPolicy == PoolingPolicy.PooledDirect /* preferDirect */);

    this.poolingPolicy = poolingPolicy;
    this.outOfMemoryPolicy = outOfMemoryPolicy;
    if (outOfMemoryListener == null) {
        this.outOfMemoryListener = (v) -> {
            log.error("Unable to allocate memory", v);
        };//from  w w w.  j  av  a  2s.  c o  m
    } else {
        this.outOfMemoryListener = outOfMemoryListener;
    }

    if (poolingPolicy == PoolingPolicy.PooledDirect) {
        if (pooledAllocator == null) {
            if (poolingConcurrency == PooledByteBufAllocator.defaultNumDirectArena()) {
                // If all the parameters are the same as in the default Netty pool,
                // just reuse the static instance as the underlying allocator.
                this.pooledAllocator = PooledByteBufAllocator.DEFAULT;
            } else {
                this.pooledAllocator = new PooledByteBufAllocator(true /* preferDirect */,
                        poolingConcurrency /* nHeapArena */, poolingConcurrency /* nDirectArena */,
                        PooledByteBufAllocator.defaultPageSize(), PooledByteBufAllocator.defaultMaxOrder(),
                        PooledByteBufAllocator.defaultTinyCacheSize(),
                        PooledByteBufAllocator.defaultSmallCacheSize(),
                        PooledByteBufAllocator.defaultNormalCacheSize(),
                        PooledByteBufAllocator.defaultUseCacheForAllThreads());
            }
        } else {
            this.pooledAllocator = pooledAllocator;
        }
    } else {
        this.pooledAllocator = null;
    }

    this.unpooledAllocator = (unpooledAllocator != null) ? unpooledAllocator : UnpooledByteBufAllocator.DEFAULT;

    // The setting is static in Netty, so it will actually affect all
    // allocators
    switch (leakDetectionPolicy) {
    case Disabled:
        if (log.isDebugEnabled()) {
            log.debug("Disable Netty allocator leak detector");
        }
        ResourceLeakDetector.setLevel(Level.DISABLED);
        break;

    case Simple:
        log.info("Setting Netty allocator leak detector to Simple");
        ResourceLeakDetector.setLevel(Level.SIMPLE);
        break;

    case Advanced:
        log.info("Setting Netty allocator leak detector to Advanced");
        ResourceLeakDetector.setLevel(Level.ADVANCED);
        break;

    case Paranoid:
        log.info("Setting Netty allocator leak detector to Paranoid");
        ResourceLeakDetector.setLevel(Level.PARANOID);
        break;
    }
}

From source file:org.glowroot.agent.init.NettyInit.java

License:Apache License

public static void run() {
    if (JavaVersion.isJ9Jvm()) {
        // WebSphere crashes on startup without this workaround (at least when pointing to
        // glowroot central and using WebSphere 8.5.5.11)
        String prior = System.getProperty("io.netty.noUnsafe");
        System.setProperty("io.netty.noUnsafe", "true");
        try {// ww w . j a  v  a  2 s .  c  o m
            if (PlatformDependent.hasUnsafe()) {
                throw new IllegalStateException("Netty property to disable usage of UNSAFE was"
                        + " not set early enough, please report to the Glowroot project");
            }
        } finally {
            if (prior == null) {
                System.clearProperty("io.netty.noUnsafe");
            } else {
                System.setProperty("io.netty.noUnsafe", prior);
            }
        }
    }
    String prior = System.getProperty("io.netty.allocator.maxOrder");
    // check that the property has not been explicitly set at the command line
    // e.g. -Dorg.glowroot.agent.shaded.io.netty.allocator.maxOrder=9
    if (prior == null || prior.isEmpty()) {
        // maxOrder 11 ==> default PoolChunk size 16mb (this is Netty's default)
        // maxOrder 10 ==> default PoolChunk size 8mb (making this Glowroot's default)
        // maxOrder 9 ==> default PoolChunk size 4mb (can be set at the command line)
        // maxOrder 8 ==> default PoolChunk size 2mb (can be set at the command line)
        System.setProperty("io.netty.allocator.maxOrder", "10");
        try {
            // the call to PooledByteBufAllocator.defaultMaxOrder() forces it to initialize
            // only logging warning if shaded, since this is always too late to initialize Netty
            // when running unshaded tests (which initialize Netty early via GrpcServerWrapper)
            if (PooledByteBufAllocator.defaultMaxOrder() != 10 && isShaded()) {
                logger.warn("Netty property to reduce the default pool chunk size was not set"
                        + " early enough, please report to the Glowroot project");
            }
        } finally {
            if (prior == null) {
                System.clearProperty("io.netty.allocator.maxOrder");
            } else {
                System.setProperty("io.netty.allocator.maxOrder", prior);
            }
        }
    }
}