-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate netty boss and worker groups to improve the graceful shutdown. #178
Merged
mashhurs
merged 1 commit into
logstash-plugins:main
from
mashhurs:graceful-shutdown-improvement
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.8.1 | ||
3.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ public class NettyHttpServer implements Runnable, Closeable { | |
private final int port; | ||
private final int connectionBacklog = 128; | ||
|
||
private final EventLoopGroup bossGroup; | ||
private final EventLoopGroup processorGroup; | ||
private final ThreadPoolExecutor executorGroup; | ||
private final HttpResponseStatus responseStatus; | ||
|
@@ -37,8 +38,14 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler, | |
this.host = host; | ||
this.port = port; | ||
this.responseStatus = HttpResponseStatus.valueOf(responseCode); | ||
|
||
// boss group is responsible for accepting incoming connections and sending to worker loop | ||
// process group is channel handler, see the https://github.com/netty/netty/discussions/13305 | ||
// see the https://github.com/netty/netty/discussions/11808#discussioncomment-1610918 for why separation is good | ||
bossGroup = new NioEventLoopGroup(1, daemonThreadFactory("http-input-connector")); | ||
processorGroup = new NioEventLoopGroup(threads, daemonThreadFactory("http-input-processor")); | ||
|
||
// event handler group | ||
executorGroup = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, | ||
new ArrayBlockingQueue<>(maxPendingRequests), daemonThreadFactory("http-input-handler-executor"), | ||
new CustomRejectedExecutionHandler()); | ||
|
@@ -51,7 +58,7 @@ public NettyHttpServer(String host, int port, IMessageHandler messageHandler, | |
} | ||
|
||
serverBootstrap = new ServerBootstrap() | ||
.group(processorGroup) | ||
.group(bossGroup, processorGroup) | ||
.channel(NioServerSocketChannel.class) | ||
.option(ChannelOption.SO_BACKLOG, connectionBacklog) | ||
.childOption(ChannelOption.SO_KEEPALIVE, true) | ||
|
@@ -73,7 +80,9 @@ public void run() { | |
public void close() { | ||
try { | ||
// stop accepting new connections first | ||
processorGroup.shutdownGracefully(0, 10, TimeUnit.SECONDS).sync(); | ||
bossGroup.shutdownGracefully().sync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review note: As my understanding, |
||
// stop the worker group | ||
processorGroup.shutdownGracefully().sync(); | ||
// then shutdown the message handler executor | ||
executorGroup.shutdown(); | ||
try { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review note: I think single thread for 128 backlog should be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't apply the same also to Beats logstash-plugins/logstash-input-beats#500 at the boss group creation https://github.com/logstash-plugins/logstash-input-beats/pull/500/files#diff-f41780ec08fd274c56c0bdf129a08f4ca42214dac2beb109ef6f789a9a349144R57?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we took offline discussion, I have kept current thread config but added TODO to follow up: