Skip to content

Commit 9fb7776

Browse files
committed
Log alloc description after netty processors set (#62741)
Currently we log the NettyAllocator description when the netty plugin is created. Unfortunately, this hits certain static fields in Netty which triggers the settings of the number of CPU processors. This conflicts with out Elasticsearch behavior to override this based on a setting. This commit resolves the issue by logging after the processors have been set.
1 parent 9a422bd commit 9fb7776

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public Netty4HttpServerTransport(Settings settings, NetworkService networkServic
150150
SharedGroupFactory sharedGroupFactory) {
151151
super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings);
152152
Netty4Utils.setAvailableProcessors(EsExecutors.NODE_PROCESSORS_SETTING.get(settings));
153+
NettyAllocator.logAllocatorDescriptionIfNeeded();
153154
this.sharedGroupFactory = sharedGroupFactory;
154155

155156
this.maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE.get(settings);

modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.elasticsearch.transport;
2121

22-
import org.apache.logging.log4j.LogManager;
23-
import org.apache.logging.log4j.Logger;
2422
import org.apache.lucene.util.SetOnce;
2523
import org.elasticsearch.Version;
2624
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@@ -51,14 +49,8 @@ public class Netty4Plugin extends Plugin implements NetworkPlugin {
5149
public static final String NETTY_TRANSPORT_NAME = "netty4";
5250
public static final String NETTY_HTTP_TRANSPORT_NAME = "netty4";
5351

54-
private static final Logger logger = LogManager.getLogger(Netty4Plugin.class);
55-
5652
private final SetOnce<SharedGroupFactory> groupFactory = new SetOnce<>();
5753

58-
public Netty4Plugin() {
59-
logger.info("creating NettyAllocator with the following configs: " + NettyAllocator.getAllocatorDescription());
60-
}
61-
6254
@Override
6355
public List<Setting<?>> getSettings() {
6456
return Arrays.asList(

modules/transport-netty4/src/main/java/org/elasticsearch/transport/NettyAllocator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@
2828
import io.netty.channel.ServerChannel;
2929
import io.netty.channel.socket.nio.NioServerSocketChannel;
3030
import io.netty.channel.socket.nio.NioSocketChannel;
31+
import org.apache.logging.log4j.LogManager;
32+
import org.apache.logging.log4j.Logger;
3133
import org.elasticsearch.common.Booleans;
3234
import org.elasticsearch.common.unit.ByteSizeValue;
3335
import org.elasticsearch.monitor.jvm.JvmInfo;
3436

37+
import java.util.concurrent.atomic.AtomicBoolean;
38+
3539
public class NettyAllocator {
3640

41+
private static final Logger logger = LogManager.getLogger(NettyAllocator.class);
42+
private static final AtomicBoolean descriptionLogged = new AtomicBoolean(false);
43+
3744
private static final ByteBufAllocator ALLOCATOR;
3845
private static final String DESCRIPTION;
3946

@@ -96,6 +103,12 @@ public class NettyAllocator {
96103
}
97104
}
98105

106+
public static void logAllocatorDescriptionIfNeeded() {
107+
if (descriptionLogged.compareAndSet(false, true)) {
108+
logger.info("creating NettyAllocator with the following configs: " + NettyAllocator.getAllocatorDescription());
109+
}
110+
}
111+
99112
public static ByteBufAllocator getAllocator() {
100113
return ALLOCATOR;
101114
}

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public Netty4Transport(Settings settings, Version version, ThreadPool threadPool
104104
CircuitBreakerService circuitBreakerService, SharedGroupFactory sharedGroupFactory) {
105105
super(settings, version, threadPool, pageCacheRecycler, circuitBreakerService, namedWriteableRegistry, networkService);
106106
Netty4Utils.setAvailableProcessors(EsExecutors.NODE_PROCESSORS_SETTING.get(settings));
107+
NettyAllocator.logAllocatorDescriptionIfNeeded();
107108
this.sharedGroupFactory = sharedGroupFactory;
108109

109110
// See AdaptiveReceiveBufferSizePredictor#DEFAULT_XXX for default values in netty..., we can use higher ones for us, even fixed one

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
public class Netty4Utils {
4040

41-
private static AtomicBoolean isAvailableProcessorsSet = new AtomicBoolean();
41+
private static final AtomicBoolean isAvailableProcessorsSet = new AtomicBoolean();
4242

4343
/**
4444
* Set the number of available processors that Netty uses for sizing various resources (e.g., thread pools).

0 commit comments

Comments
 (0)