From 00c0f7d4d927ffdbf78339e84bf9bdbfaef5b319 Mon Sep 17 00:00:00 2001 From: Aviana Cruz Date: Sat, 8 Apr 2023 16:39:16 +0000 Subject: [PATCH] Add support for io_uring --- gradle/libs.versions.toml | 1 + proxy/build.gradle.kts | 3 +++ .../proxy/network/ConnectionManager.java | 6 +++--- .../proxy/network/TransportType.java | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b3d0071b6..8775b557b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -51,6 +51,7 @@ netty-codec-haproxy = { module = "io.netty:netty-codec-haproxy", version.ref = " 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-iouring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version = "0.0.24.Final" } netty-transport-native-kqueue = { module = "io.netty:netty-transport-native-kqueue", version.ref = "netty" } nightconfig = "com.electronwill.night-config:toml:3.6.7" slf4j = "org.slf4j:slf4j-api:2.0.7" diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index b3026977a..6406b1fec 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -107,6 +107,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/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 23fd55c7d..953305f53 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -65,7 +65,7 @@ public final class ConnectionManager { private final HttpClient httpClient; /** - * Initalizes the {@code ConnectionManager}. + * Initializes the {@code ConnectionManager}. * * @param server a reference to the Velocity server */ @@ -104,7 +104,7 @@ public final class ConnectionManager { .childOption(ChannelOption.IP_TOS, 0x18) .localAddress(address); - if (server.getConfiguration().useTcpFastOpen()) { + if (transportType != TransportType.NIO && server.getConfiguration().useTcpFastOpen()) { bootstrap.option(ChannelOption.TCP_FASTOPEN, 3); } @@ -167,7 +167,7 @@ public final class ConnectionManager { this.server.getConfiguration().getConnectTimeout()) .group(group == null ? this.workerGroup : group) .resolver(this.resolver.asGroup()); - if (server.getConfiguration().useTcpFastOpen()) { + if (transportType != TransportType.NIO && server.getConfiguration().useTcpFastOpen()) { bootstrap.option(ChannelOption.TCP_FASTOPEN_CONNECT, true); } return bootstrap; 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..e2d7f2618 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java @@ -37,6 +37,11 @@ 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.incubator.channel.uring.IOUring; +import io.netty.incubator.channel.uring.IOUringDatagramChannel; +import io.netty.incubator.channel.uring.IOUringEventLoopGroup; +import io.netty.incubator.channel.uring.IOUringServerSocketChannel; +import io.netty.incubator.channel.uring.IOUringSocketChannel; import java.util.concurrent.ThreadFactory; import java.util.function.BiFunction; @@ -48,6 +53,10 @@ public enum TransportType { NioSocketChannel::new, NioDatagramChannel::new, (name, type) -> new NioEventLoopGroup(0, createThreadFactory(name, type))), + IO_URING("io_uring", IOUringServerSocketChannel::new, + IOUringSocketChannel::new, + IOUringDatagramChannel::new, + (name, type) -> new IOUringEventLoopGroup(0, createThreadFactory(name, type))), EPOLL("epoll", EpollServerSocketChannel::new, EpollSocketChannel::new, EpollDatagramChannel::new, @@ -98,6 +107,10 @@ public enum TransportType { return NIO; } + if (Boolean.getBoolean("velocity.enable-iouring") && IOUring.isAvailable()) { + return IO_URING; + } + if (Epoll.isAvailable()) { return EPOLL; }