2929import io .netty .channel .ChannelOption ;
3030import io .netty .channel .FixedRecvByteBufAllocator ;
3131import io .netty .channel .RecvByteBufAllocator ;
32- import io .netty .channel .nio .NioEventLoopGroup ;
3332import io .netty .channel .socket .nio .NioChannelOption ;
3433import io .netty .handler .codec .ByteToMessageDecoder ;
3534import io .netty .handler .codec .http .HttpContentCompressor ;
6261import org .elasticsearch .http .HttpServerChannel ;
6362import org .elasticsearch .http .netty4 .cors .Netty4CorsHandler ;
6463import org .elasticsearch .threadpool .ThreadPool ;
64+ import org .elasticsearch .transport .SharedGroupFactory ;
6565import org .elasticsearch .transport .NettyAllocator ;
6666import org .elasticsearch .transport .netty4 .Netty4Utils ;
6767
6868import java .net .InetSocketAddress ;
6969import java .net .SocketOption ;
7070import java .util .concurrent .TimeUnit ;
7171
72- import static org .elasticsearch .common .util .concurrent .EsExecutors .daemonThreadFactory ;
7372import static org .elasticsearch .http .HttpTransportSettings .SETTING_HTTP_MAX_CHUNK_SIZE ;
7473import static org .elasticsearch .http .HttpTransportSettings .SETTING_HTTP_MAX_CONTENT_LENGTH ;
7574import static org .elasticsearch .http .HttpTransportSettings .SETTING_HTTP_MAX_HEADER_SIZE ;
@@ -126,9 +125,7 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
126125 // Netty's CompositeByteBuf implementation does not allow less than two components.
127126 }, s -> Setting .parseInt (s , 2 , Integer .MAX_VALUE , SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS ), Property .NodeScope );
128127
129- public static final Setting <Integer > SETTING_HTTP_WORKER_COUNT = new Setting <>("http.netty.worker_count" ,
130- (s ) -> Integer .toString (EsExecutors .allocatedProcessors (s ) * 2 ),
131- (s ) -> Setting .parseInt (s , 1 , "http.netty.worker_count" ), Property .NodeScope );
128+ public static final Setting <Integer > SETTING_HTTP_WORKER_COUNT = Setting .intSetting ("http.netty.worker_count" , 0 , Property .NodeScope );
132129
133130 public static final Setting <ByteSizeValue > SETTING_HTTP_NETTY_RECEIVE_PREDICTOR_SIZE =
134131 Setting .byteSizeSetting ("http.netty.receive_predictor_size" , new ByteSizeValue (64 , ByteSizeUnit .KB ), Property .NodeScope );
@@ -137,29 +134,30 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
137134 private final ByteSizeValue maxHeaderSize ;
138135 private final ByteSizeValue maxChunkSize ;
139136
140- private final int workerCount ;
141-
142137 private final int pipeliningMaxEvents ;
143138
139+ private final SharedGroupFactory sharedGroupFactory ;
144140 private final RecvByteBufAllocator recvByteBufAllocator ;
145141 private final int readTimeoutMillis ;
146142
147143 private final int maxCompositeBufferComponents ;
148144
149145 private volatile ServerBootstrap serverBootstrap ;
146+ private volatile SharedGroupFactory .SharedGroup sharedGroup ;
150147
151148 public Netty4HttpServerTransport (Settings settings , NetworkService networkService , BigArrays bigArrays , ThreadPool threadPool ,
152- NamedXContentRegistry xContentRegistry , Dispatcher dispatcher , ClusterSettings clusterSettings ) {
149+ NamedXContentRegistry xContentRegistry , Dispatcher dispatcher , ClusterSettings clusterSettings ,
150+ SharedGroupFactory sharedGroupFactory ) {
153151 super (settings , networkService , bigArrays , threadPool , xContentRegistry , dispatcher , clusterSettings );
154152 Netty4Utils .setAvailableProcessors (EsExecutors .NODE_PROCESSORS_SETTING .get (settings ));
153+ this .sharedGroupFactory = sharedGroupFactory ;
155154
156155 this .maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE .get (settings );
157156 this .maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE .get (settings );
158157 this .maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH .get (settings );
159158 this .pipeliningMaxEvents = SETTING_PIPELINING_MAX_EVENTS .get (settings );
160159
161160 this .maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS .get (settings );
162- this .workerCount = SETTING_HTTP_WORKER_COUNT .get (settings );
163161
164162 this .readTimeoutMillis = Math .toIntExact (SETTING_HTTP_READ_TIMEOUT .get (settings ).getMillis ());
165163
@@ -180,10 +178,10 @@ public Settings settings() {
180178 protected void doStart () {
181179 boolean success = false ;
182180 try {
181+ sharedGroup = sharedGroupFactory .getHttpGroup ();
183182 serverBootstrap = new ServerBootstrap ();
184183
185- serverBootstrap .group (new NioEventLoopGroup (workerCount , daemonThreadFactory (settings ,
186- HTTP_SERVER_WORKER_THREAD_NAME_PREFIX )));
184+ serverBootstrap .group (sharedGroup .getLowLevelGroup ());
187185
188186 // NettyAllocator will return the channel type designed to work with the configuredAllocator
189187 serverBootstrap .channel (NettyAllocator .getServerChannelType ());
@@ -260,9 +258,9 @@ protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Excepti
260258
261259 @ Override
262260 protected void stopInternal () {
263- if (serverBootstrap != null ) {
264- serverBootstrap . config (). group (). shutdownGracefully ( 0 , 5 , TimeUnit . SECONDS ). awaitUninterruptibly ();
265- serverBootstrap = null ;
261+ if (sharedGroup != null ) {
262+ sharedGroup . shutdown ();
263+ sharedGroup = null ;
266264 }
267265 }
268266
0 commit comments