This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 7ace05ca9 RATIS-1899. Use EpollEventLoopGroup for Netty Proxies (#932)
7ace05ca9 is described below
commit 7ace05ca981d6af94e21899b672dd357f3843b6a
Author: Ivan Andika <[email protected]>
AuthorDate: Mon Oct 9 00:52:23 2023 +0800
RATIS-1899. Use EpollEventLoopGroup for Netty Proxies (#932)
---
.../main/java/org/apache/ratis/netty/NettyClient.java | 3 +--
.../java/org/apache/ratis/netty/NettyConfigKeys.java | 18 ++++++++++++++++++
.../java/org/apache/ratis/netty/NettyRpcProxy.java | 4 ++--
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyClient.java
b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyClient.java
index 849d24266..0cf4bd383 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyClient.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyClient.java
@@ -23,7 +23,6 @@ import
org.apache.ratis.thirdparty.io.netty.channel.ChannelFuture;
import org.apache.ratis.thirdparty.io.netty.channel.ChannelInitializer;
import org.apache.ratis.thirdparty.io.netty.channel.EventLoopGroup;
import org.apache.ratis.thirdparty.io.netty.channel.socket.SocketChannel;
-import
org.apache.ratis.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;
import org.apache.ratis.thirdparty.io.netty.handler.logging.LogLevel;
import org.apache.ratis.thirdparty.io.netty.handler.logging.LoggingHandler;
import org.apache.ratis.util.JavaUtils;
@@ -47,7 +46,7 @@ public class NettyClient implements Closeable {
lifeCycle.startAndTransition(
() -> channel = new Bootstrap()
.group(group)
- .channel(NioSocketChannel.class)
+ .channel(NettyUtils.getSocketChannelClass(group))
.handler(new LoggingHandler(LogLevel.INFO))
.handler(initializer)
.connect(address)
diff --git
a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyConfigKeys.java
b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyConfigKeys.java
index 20832873d..98b1a6d74 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyConfigKeys.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyConfigKeys.java
@@ -76,6 +76,24 @@ public interface NettyConfigKeys {
}
}
+ interface Client {
+ Logger LOG = LoggerFactory.getLogger(Client.class);
+ static Consumer<String> getDefaultLog() {
+ return LOG::debug;
+ }
+
+ String PREFIX = NettyConfigKeys.PREFIX + ".client";
+
+ String USE_EPOLL_KEY = PREFIX + ".use-epoll";
+ boolean USE_EPOLL_DEFAULT = true;
+ static boolean useEpoll(RaftProperties properties) {
+ return getBoolean(properties::getBoolean, USE_EPOLL_KEY,
USE_EPOLL_DEFAULT, getDefaultLog());
+ }
+ static void setUseEpoll(RaftProperties properties, boolean enable) {
+ setBoolean(properties::setBoolean, USE_EPOLL_KEY, enable);
+ }
+ }
+
interface DataStream {
Logger LOG = LoggerFactory.getLogger(DataStream.class);
static Consumer<String> getDefaultLog() {
diff --git
a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
index 74f92ce3f..b7a04b050 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyRpcProxy.java
@@ -22,7 +22,6 @@ import org.apache.ratis.conf.RaftProperties;
import org.apache.ratis.protocol.RaftPeer;
import org.apache.ratis.protocol.exceptions.TimeoutIOException;
import org.apache.ratis.thirdparty.io.netty.channel.*;
-import org.apache.ratis.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
import org.apache.ratis.thirdparty.io.netty.channel.socket.SocketChannel;
import
org.apache.ratis.thirdparty.io.netty.handler.codec.protobuf.ProtobufDecoder;
import
org.apache.ratis.thirdparty.io.netty.handler.codec.protobuf.ProtobufEncoder;
@@ -52,7 +51,8 @@ public class NettyRpcProxy implements Closeable {
private final EventLoopGroup group;
public PeerMap(String name, RaftProperties properties) {
- this(name, properties, new NioEventLoopGroup());
+ this(name, properties, NettyUtils.newEventLoopGroup(name, 0,
+ NettyConfigKeys.Client.useEpoll(properties)));
}
private PeerMap(String name, RaftProperties properties, EventLoopGroup
group) {