From 4deaf2ed1a2500e715493d100d46f2a769ca3e2e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 12 Jul 2024 22:02:13 -0400 Subject: [PATCH] Bump to Netty 4.2.0.Alpha2, add io_uring transport --- gradle/libs.versions.toml | 3 +- proxy/build.gradle.kts | 3 ++ .../proxy/network/TransportType.java | 37 +++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 510c4d62a..a2fb72cdd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ configurate3 = "3.7.3" configurate4 = "4.1.2" flare = "2.0.1" log4j = "2.22.1" -netty = "4.1.106.Final" +netty = "4.2.0.Alpha2" [plugins] indra-publishing = "net.kyori.indra.publishing:2.0.6" @@ -53,6 +53,7 @@ netty-codec-http = { module = "io.netty:netty-codec-http", version.ref = "netty" netty-handler = { module = "io.netty:netty-handler", version.ref = "netty" } netty-transport-native-epoll = { module = "io.netty:netty-transport-native-epoll", version.ref = "netty" } netty-transport-native-kqueue = { module = "io.netty:netty-transport-native-kqueue", version.ref = "netty" } +netty-transport-native-iouring = { module = "io.netty:netty-transport-native-io_uring", version.ref = "netty" } nightconfig = "com.electronwill.night-config:toml:3.6.7" slf4j = "org.slf4j:slf4j-api:2.0.12" snakeyaml = "org.yaml:snakeyaml:1.33" diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index 5e1387b06..81c6d9684 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -108,6 +108,9 @@ dependencies { implementation(libs.netty.transport.native.epoll) implementation(variantOf(libs.netty.transport.native.epoll) { classifier("linux-x86_64") }) implementation(variantOf(libs.netty.transport.native.epoll) { classifier("linux-aarch_64") }) + implementation(libs.netty.transport.native.iouring) + implementation(variantOf(libs.netty.transport.native.iouring) { classifier("linux-x86_64") }) + implementation(variantOf(libs.netty.transport.native.iouring) { classifier("linux-aarch_64") }) implementation(libs.netty.transport.native.kqueue) implementation(variantOf(libs.netty.transport.native.kqueue) { classifier("osx-x86_64") }) implementation(variantOf(libs.netty.transport.native.kqueue) { classifier("osx-aarch_64") }) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java index 6cbdfd8c5..543c85824 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java @@ -20,25 +20,31 @@ package com.velocitypowered.proxy.network; import com.velocitypowered.proxy.util.concurrent.VelocityNettyThreadFactory; import io.netty.channel.ChannelFactory; import io.netty.channel.EventLoopGroup; +import io.netty.channel.IoHandlerFactory; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.EpollDatagramChannel; -import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollIoHandler; import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.kqueue.KQueue; import io.netty.channel.kqueue.KQueueDatagramChannel; -import io.netty.channel.kqueue.KQueueEventLoopGroup; +import io.netty.channel.kqueue.KQueueIoHandler; import io.netty.channel.kqueue.KQueueServerSocketChannel; import io.netty.channel.kqueue.KQueueSocketChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.channel.uring.IoUring; +import io.netty.channel.uring.IoUringDatagramChannel; +import io.netty.channel.uring.IoUringIoHandler; +import io.netty.channel.uring.IoUringServerSocketChannel; +import io.netty.channel.uring.IoUringSocketChannel; import java.util.concurrent.ThreadFactory; -import java.util.function.BiFunction; /** * Enumerates the supported transports for Velocity. @@ -47,32 +53,36 @@ public enum TransportType { NIO("NIO", NioServerSocketChannel::new, NioSocketChannel::new, NioDatagramChannel::new, - (name, type) -> new NioEventLoopGroup(0, createThreadFactory(name, type))), + NioIoHandler.newFactory()), EPOLL("epoll", EpollServerSocketChannel::new, EpollSocketChannel::new, EpollDatagramChannel::new, - (name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type))), + EpollIoHandler.newFactory()), KQUEUE("kqueue", KQueueServerSocketChannel::new, KQueueSocketChannel::new, KQueueDatagramChannel::new, - (name, type) -> new KQueueEventLoopGroup(0, createThreadFactory(name, type))); + KQueueIoHandler.newFactory()), + IO_URING("io_uring", IoUringServerSocketChannel::new, + IoUringSocketChannel::new, + IoUringDatagramChannel::new, + IoUringIoHandler.newFactory()); final String name; final ChannelFactory serverSocketChannelFactory; final ChannelFactory socketChannelFactory; final ChannelFactory datagramChannelFactory; - final BiFunction eventLoopGroupFactory; + final IoHandlerFactory ioHandlerFactory; TransportType(final String name, final ChannelFactory serverSocketChannelFactory, final ChannelFactory socketChannelFactory, final ChannelFactory datagramChannelFactory, - final BiFunction eventLoopGroupFactory) { + final IoHandlerFactory ioHandlerFactory) { this.name = name; this.serverSocketChannelFactory = serverSocketChannelFactory; this.socketChannelFactory = socketChannelFactory; this.datagramChannelFactory = datagramChannelFactory; - this.eventLoopGroupFactory = eventLoopGroupFactory; + this.ioHandlerFactory = ioHandlerFactory; } @Override @@ -81,7 +91,8 @@ public enum TransportType { } public EventLoopGroup createEventLoopGroup(final Type type) { - return this.eventLoopGroupFactory.apply(this.name, type); + return new MultiThreadIoEventLoopGroup( + 0, createThreadFactory(this.name, type), this.ioHandlerFactory); } private static ThreadFactory createThreadFactory(final String name, final Type type) { @@ -98,6 +109,10 @@ public enum TransportType { return NIO; } + if (IoUring.isAvailable()) { + return IO_URING; + } + if (Epoll.isAvailable()) { return EPOLL; }