Skip to content

Commit 8bcb7da

Browse files
author
Edward De-Faria
committed
Pull request logstash-plugins#15: merge main
Merge in THOT/logstash-input-http from dev-edefaria to prod * commit 'b9021d8e9815b267a9023e9f286c96c3eeb20ac7': Separate netty boss and worker groups to improve the graceful shutdown process.
2 parents 267c856 + b9021d8 commit 8bcb7da

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.9.0
2+
- Netty boss and worker groups are separated [#178](https://github.com/logstash-plugins/logstash-input-http/pull/178)
3+
As a result, when shutdown requested incoming connections are closed first and improved graceful shutdown
4+
15
## 3.8.1
26
- bump netty to 4.1.109 [#173](https://github.com/logstash-plugins/logstash-input-http/pull/173)
37

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.8.1
1+
3.9.0

src/main/java/org/logstash/plugins/inputs/http/NettyHttpServer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class NettyHttpServer implements Runnable, Closeable {
2626
private final int port;
2727
private final int connectionBacklog = 128;
2828

29+
private final EventLoopGroup bossGroup;
2930
private final EventLoopGroup processorGroup;
3031
private final ThreadPoolExecutor executorGroup;
3132
private final HttpResponseStatus responseStatus;
@@ -37,8 +38,14 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler,
3738
this.host = host;
3839
this.port = port;
3940
this.responseStatus = HttpResponseStatus.valueOf(responseCode);
41+
42+
// boss group is responsible for accepting incoming connections and sending to worker loop
43+
// process group is channel handler, see the https://github.com/netty/netty/discussions/13305
44+
// see the https://github.com/netty/netty/discussions/11808#discussioncomment-1610918 for why separation is good
45+
bossGroup = new NioEventLoopGroup(1, daemonThreadFactory("http-input-connector"));
4046
processorGroup = new NioEventLoopGroup(threads, daemonThreadFactory("http-input-processor"));
4147

48+
// event handler group
4249
executorGroup = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
4350
new ArrayBlockingQueue<>(maxPendingRequests), daemonThreadFactory("http-input-handler-executor"),
4451
new CustomRejectedExecutionHandler());
@@ -51,7 +58,7 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler,
5158
}
5259

5360
serverBootstrap = new ServerBootstrap()
54-
.group(processorGroup)
61+
.group(bossGroup, processorGroup)
5562
.channel(NioServerSocketChannel.class)
5663
.option(ChannelOption.SO_BACKLOG, connectionBacklog)
5764
.childOption(ChannelOption.SO_KEEPALIVE, true)
@@ -73,7 +80,9 @@ public void run() {
7380
public void close() {
7481
try {
7582
// stop accepting new connections first
76-
processorGroup.shutdownGracefully(0, 10, TimeUnit.SECONDS).sync();
83+
bossGroup.shutdownGracefully().sync();
84+
// stop the worker group
85+
processorGroup.shutdownGracefully().sync();
7786
// then shutdown the message handler executor
7887
executorGroup.shutdown();
7988
try {

0 commit comments

Comments
 (0)