Skip to content
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

Correctly detect if Epoll is available #6256

Merged
1 commit merged into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.netty.channel.ServerChannel;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.epoll.EpollSocketChannel;
Expand Down Expand Up @@ -263,7 +264,7 @@ public CompletableFuture<MessagingService> start() {
return CompletableFuture.completedFuture(this);
}

initEventLoopGroup();
initTransport();
return bootstrapServer()
.thenRun(
() -> {
Expand Down Expand Up @@ -332,22 +333,24 @@ public CompletableFuture<Void> stop() {
return CompletableFuture.completedFuture(null);
}

private void initEventLoopGroup() {
// try Epoll first and if that does work, use nio.
try {
clientGroup =
new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-client-%d", log));
serverGroup =
new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-server-%d", log));
serverChannelClass = EpollServerSocketChannel.class;
clientChannelClass = EpollSocketChannel.class;
return;
} catch (final Exception e) {
log.debug(
"Failed to initialize native (epoll) transport. " + "Reason: {}. Proceeding with nio.",
e.getMessage(),
e);
private void initTransport() {
if (Epoll.isAvailable()) {
initEpollTransport();
} else {
initNioTransport();
}
}

private void initEpollTransport() {
clientGroup =
new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-client-%d", log));
serverGroup =
new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-server-%d", log));
serverChannelClass = EpollServerSocketChannel.class;
clientChannelClass = EpollSocketChannel.class;
}

private void initNioTransport() {
clientGroup =
new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-client-%d", log));
serverGroup =
Expand Down