Skip to content

Commit

Permalink
netty: log the selection of allocators (grpc#6930)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkun83 authored and dfawley committed Jan 15, 2021
1 parent dcaff20 commit 1fde8bf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion netty/src/main/java/io/grpc/netty/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,36 @@ private static final class ByteBufAllocatorPreferHeapHolder {
public static ByteBufAllocator getByteBufAllocator(boolean forceHeapBuffer) {
if (Boolean.parseBoolean(
System.getProperty("io.grpc.netty.useCustomAllocator", "true"))) {
if (forceHeapBuffer || !PooledByteBufAllocator.defaultPreferDirect()) {
boolean defaultPreferDirect = PooledByteBufAllocator.defaultPreferDirect();
logger.log(
Level.FINE,
String.format(
"Using custom allocator: forceHeapBuffer=%s, defaultPreferDirect=%s",
forceHeapBuffer,
defaultPreferDirect));
if (forceHeapBuffer || !defaultPreferDirect) {
return ByteBufAllocatorPreferHeapHolder.allocator;
} else {
return ByteBufAllocatorPreferDirectHolder.allocator;
}
} else {
logger.log(Level.FINE, "Using default allocator");
return ByteBufAllocator.DEFAULT;
}
}

private static ByteBufAllocator createByteBufAllocator(boolean preferDirect) {
int maxOrder;
logger.log(Level.FINE, "Creating allocator, preferDirect=" + preferDirect);
if (System.getProperty("io.netty.allocator.maxOrder") == null) {
// See the implementation of PooledByteBufAllocator. DEFAULT_MAX_ORDER in there is
// 11, which makes chunk size to be 8192 << 11 = 16 MiB. We want the chunk size to be
// 2MiB, thus reducing the maxOrder to 8.
maxOrder = 8;
logger.log(Level.FINE, "Forcing maxOrder=" + maxOrder);
} else {
maxOrder = PooledByteBufAllocator.defaultMaxOrder();
logger.log(Level.FINE, "Using default maxOrder=" + maxOrder);
}
return new PooledByteBufAllocator(
preferDirect,
Expand Down

0 comments on commit 1fde8bf

Please sign in to comment.