Allow overriding the default allocator properties and log them / Prettier log

This commit is contained in:
Trustin Lee 2013-04-03 12:08:01 +09:00
parent 0f3dc0409a
commit 2ffa083d3c
4 changed files with 57 additions and 8 deletions

View File

@ -18,20 +18,65 @@ package io.netty.buffer;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public class PooledByteBufAllocator extends AbstractByteBufAllocator { public class PooledByteBufAllocator extends AbstractByteBufAllocator {
private static final int DEFAULT_NUM_HEAP_ARENA = Runtime.getRuntime().availableProcessors(); private static final InternalLogger logger = InternalLoggerFactory.getInstance(PooledByteBufAllocator.class);
private static final int DEFAULT_NUM_DIRECT_ARENA = Runtime.getRuntime().availableProcessors();
private static final int DEFAULT_PAGE_SIZE = 8192; private static final int DEFAULT_NUM_HEAP_ARENA = Math.max(1, SystemPropertyUtil.getInt(
private static final int DEFAULT_MAX_ORDER = 11; // 8192 << 11 = 16 MiB per chunk "io.netty.allocator.numHeapArenas", Runtime.getRuntime().availableProcessors()));
private static final int DEFAULT_NUM_DIRECT_ARENA = Math.max(1, SystemPropertyUtil.getInt(
"io.netty.allocator.numDirectArenas", Runtime.getRuntime().availableProcessors()));
private static final int DEFAULT_PAGE_SIZE;
private static final int DEFAULT_MAX_ORDER; // 8192 << 11 = 16 MiB per chunk
private static final int MIN_PAGE_SIZE = 4096; private static final int MIN_PAGE_SIZE = 4096;
private static final int MAX_CHUNK_SIZE = (int) (((long) Integer.MAX_VALUE + 1) / 2); private static final int MAX_CHUNK_SIZE = (int) (((long) Integer.MAX_VALUE + 1) / 2);
static {
int defaultPageSize = SystemPropertyUtil.getInt("io.netty.allocator.pageSize", 8192);
Throwable pageSizeFallbackCause = null;
try {
validateAndCalculatePageShifts(defaultPageSize);
} catch (Throwable t) {
pageSizeFallbackCause = t;
defaultPageSize = 8192;
}
DEFAULT_PAGE_SIZE = defaultPageSize;
int defaultMaxOrder = SystemPropertyUtil.getInt("io.netty.allocator.maxOrder", 11);
Throwable maxOrderFallbackCause = null;
try {
validateAndCalculateChunkSize(DEFAULT_PAGE_SIZE, defaultMaxOrder);
} catch (Throwable t) {
maxOrderFallbackCause = t;
defaultMaxOrder = 11;
}
DEFAULT_MAX_ORDER = defaultMaxOrder;
if (logger.isDebugEnabled()) {
logger.debug("io.netty.allocator.numHeapArenas: {}", DEFAULT_NUM_HEAP_ARENA);
logger.debug("io.netty.allocator.numDirectArenas: {}", DEFAULT_NUM_DIRECT_ARENA);
if (pageSizeFallbackCause == null) {
logger.debug("io.netty.allocator.pageSize: {}", DEFAULT_PAGE_SIZE);
} else {
logger.debug("io.netty.allocator.pageSize: {}", DEFAULT_PAGE_SIZE, pageSizeFallbackCause);
}
if (maxOrderFallbackCause == null) {
logger.debug("io.netty.allocator.maxOrder: {}", DEFAULT_MAX_ORDER);
} else {
logger.debug("io.netty.allocator.maxOrder: {}", DEFAULT_MAX_ORDER, maxOrderFallbackCause);
}
logger.debug("io.netty.allocator.chunkSize: {}", DEFAULT_PAGE_SIZE << DEFAULT_MAX_ORDER);
}
}
public static final PooledByteBufAllocator DEFAULT = public static final PooledByteBufAllocator DEFAULT =
new PooledByteBufAllocator(PlatformDependent.directBufferPreferred()); new PooledByteBufAllocator(PlatformDependent.directBufferPreferred());

View File

@ -59,7 +59,11 @@ final class JavassistTypeParameterMatcherGenerator {
method.setAccessible(true); method.setAccessible(true);
Class<?> generated = (Class<?>) method.invoke(classLoader, className, byteCode, 0, byteCode.length); Class<?> generated = (Class<?>) method.invoke(classLoader, className, byteCode, 0, byteCode.length);
logger.debug("Generated: {}", generated.getName()); if (type != Object.class) {
logger.debug("Generated: {}", generated.getName());
} else {
// Object.class is only used when checking if Javassist is available.
}
return (TypeParameterMatcher) generated.newInstance(); return (TypeParameterMatcher) generated.newInstance();
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw e; throw e;

View File

@ -482,7 +482,7 @@ public final class PlatformDependent {
logger.debug("Javassist: unavailable"); logger.debug("Javassist: unavailable");
logger.warn( logger.warn(
"You don't have Javassist in your class path or you don't have enough permission " + "You don't have Javassist in your class path or you don't have enough permission " +
"to load dynamically generated classes. Please check the configuration for better performance."); "to load dynamically generated classes. Please check the configuration for better performance.");
return false; return false;
} }
} }

View File

@ -90,9 +90,9 @@ final class PlatformDependent0 {
"copyMemory", "copyMemory",
new Class[] { Object.class, long.class, Object.class, long.class, long.class }); new Class[] { Object.class, long.class, Object.class, long.class, long.class });
logger.debug("sun.misc.Unsafe.copyMemory(Object, long, Object, long, long): available"); logger.debug("sun.misc.Unsafe.copyMemory: available");
} catch (NoSuchMethodError t) { } catch (NoSuchMethodError t) {
logger.debug("sun.misc.Unsafe.copyMemory(Object, long, Object, long, long): unavailable"); logger.debug("sun.misc.Unsafe.copyMemory: unavailable");
throw t; throw t;
} }
} catch (Throwable cause) { } catch (Throwable cause) {