Skip to content

Commit f1a87a2

Browse files
committed
feat: support io_uring
1 parent 9f388ab commit f1a87a2

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/main/java/com/alipay/remoting/config/ConfigManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public static boolean netty_epoll_lt_enabled() {
7474
return getBool(Configs.NETTY_EPOLL_LT, Configs.NETTY_EPOLL_LT_DEFAULT);
7575
}
7676

77+
public static boolean netty_io_uring() {
78+
return getBool(Configs.NETTY_IO_URING_SWITCH, Configs.NETTY_IO_URING_SWITCH_DEFAULT);
79+
}
80+
7781
// ~~~ properties for idle
7882
public static boolean tcp_idle_switch() {
7983
return getBool(Configs.TCP_IDLE_SWITCH, Configs.TCP_IDLE_SWITCH_DEFAULT);

src/main/java/com/alipay/remoting/config/Configs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class Configs {
6969
public static final String NETTY_EPOLL_SWITCH = "bolt.netty.epoll.switch";
7070
public static final String NETTY_EPOLL_SWITCH_DEFAULT = "true";
7171

72+
public static final String NETTY_IO_URING_SWITCH = "bolt.netty.io_uring.switch";
73+
public static final String NETTY_IO_URING_SWITCH_DEFAULT = "false";
74+
7275
/** Netty epoll level trigger enabled */
7376
public static final String NETTY_EPOLL_LT = "bolt.netty.epoll.lt";
7477
public static final String NETTY_EPOLL_LT_DEFAULT = "true";

src/main/java/com/alipay/remoting/util/NettyEventLoopUtil.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import io.netty.channel.socket.SocketChannel;
3434
import io.netty.channel.socket.nio.NioServerSocketChannel;
3535
import io.netty.channel.socket.nio.NioSocketChannel;
36+
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
37+
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
38+
import io.netty.incubator.channel.uring.IOUringSocketChannel;
3639

3740
/**
3841
* Utils for netty EventLoop
@@ -43,7 +46,10 @@
4346
public class NettyEventLoopUtil {
4447

4548
/** check whether epoll enabled, and it would not be changed during runtime. */
46-
private static boolean epollEnabled = ConfigManager.netty_epoll() && Epoll.isAvailable();
49+
private static final boolean epollEnabled = ConfigManager.netty_epoll()
50+
&& Epoll.isAvailable();
51+
52+
private static final boolean ioUringEnabled = ConfigManager.netty_io_uring();
4753

4854
/**
4955
* Create the right event loop according to current platform and system property, fallback to NIO when epoll not enabled.
@@ -53,22 +59,25 @@ public class NettyEventLoopUtil {
5359
* @return an EventLoopGroup suitable for the current platform
5460
*/
5561
public static EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
56-
return epollEnabled ? new EpollEventLoopGroup(nThreads, threadFactory)
57-
: new NioEventLoopGroup(nThreads, threadFactory);
62+
return ioUringEnabled ? new IOUringEventLoopGroup(nThreads, threadFactory)
63+
: epollEnabled ? new EpollEventLoopGroup(nThreads, threadFactory)
64+
: new NioEventLoopGroup(nThreads, threadFactory);
5865
}
5966

6067
/**
6168
* @return a SocketChannel class suitable for the given EventLoopGroup implementation
6269
*/
6370
public static Class<? extends SocketChannel> getClientSocketChannelClass() {
64-
return epollEnabled ? EpollSocketChannel.class : NioSocketChannel.class;
71+
return ioUringEnabled ? IOUringSocketChannel.class
72+
: epollEnabled ? EpollSocketChannel.class : NioSocketChannel.class;
6573
}
6674

6775
/**
6876
* @return a ServerSocketChannel class suitable for the given EventLoopGroup implementation
6977
*/
7078
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass() {
71-
return epollEnabled ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
79+
return ioUringEnabled ? IOUringServerSocketChannel.class
80+
: epollEnabled ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
7281
}
7382

7483
/**
@@ -77,7 +86,7 @@ public static Class<? extends ServerSocketChannel> getServerSocketChannelClass()
7786
* @param serverBootstrap server bootstrap
7887
*/
7988
public static void enableTriggeredMode(ServerBootstrap serverBootstrap) {
80-
if (epollEnabled) {
89+
if (!ioUringEnabled && epollEnabled) {
8190
if (ConfigManager.netty_epoll_lt_enabled()) {
8291
serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE,
8392
EpollMode.LEVEL_TRIGGERED);

0 commit comments

Comments
 (0)