Skip to content

Commit

Permalink
Add support for io_uring
Browse files Browse the repository at this point in the history
  • Loading branch information
skbeh committed Jun 22, 2023
1 parent bda1430 commit d864a00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
configurate = "3.7.3"
flare = "2.0.1"
log4j = "2.20.0"
netty = "4.1.90.Final"
netty = "4.1.94.Final"

[plugins]
indra-publishing = "net.kyori.indra.publishing:2.0.6"
Expand All @@ -13,7 +13,7 @@ spotless = "com.diffplug.spotless:6.12.0"
adventure-bom = "net.kyori:adventure-bom:4.13.1"
adventure-facet = "net.kyori:adventure-platform-facet:4.3.0"
asm = "org.ow2.asm:asm:9.5"
asynchttpclient = "org.asynchttpclient:async-http-client:2.12.3"
asynchttpclient = "org.asynchttpclient:async-http-client:3.0.0.Beta2"
brigadier = "com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT"
bstats = "org.bstats:bstats-base:3.0.1"
caffeine = "com.github.ben-manes.caffeine:caffeine:3.1.5"
Expand Down Expand Up @@ -43,6 +43,7 @@ netty-codec = { module = "io.netty:netty-codec", version.ref = "netty" }
netty-codec-haproxy = { module = "io.netty:netty-codec-haproxy", version.ref = "netty" }
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-iouring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version = "0.0.21.Final" }
netty-transport-native-epoll = { module = "io.netty:netty-transport-native-epoll", version.ref = "netty" }
nightconfig = "com.electronwill.night-config:toml:3.6.6"
slf4j = "org.slf4j:slf4j-api:1.7.30"
Expand Down
3 changes: 3 additions & 0 deletions proxy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,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.jopt)
implementation(libs.terminalconsoleappender)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.util.concurrent.GlobalEventExecutor;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.filter.FilterContext;
import org.asynchttpclient.filter.FilterContext.FilterContextBuilder;
import org.asynchttpclient.filter.RequestFilter;
Expand Down Expand Up @@ -73,7 +71,7 @@ public final class ConnectionManager {
private final AsyncHttpClient httpClient;

/**
* Initalizes the {@code ConnectionManager}.
* Initializes the {@code ConnectionManager}.
*
* @param server a reference to the Velocity server
*/
Expand All @@ -94,7 +92,8 @@ public ConnectionManager(VelocityServer server) {
@Override
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
return new FilterContextBuilder<>(ctx)
.request(new RequestBuilder(ctx.getRequest())
.request(ctx.getRequest()
.toBuilder()
.setNameResolver(resolver)
.build())
.build();
Expand Down Expand Up @@ -123,8 +122,8 @@ public void bind(final InetSocketAddress address) {
.childOption(ChannelOption.IP_TOS, 0x18)
.localAddress(address);

if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(EpollChannelOption.TCP_FASTOPEN, 3);
if (transportType != TransportType.NIO && server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(ChannelOption.TCP_FASTOPEN, 3);
}

bootstrap.bind()
Expand Down Expand Up @@ -186,8 +185,8 @@ public Bootstrap createWorker(@Nullable EventLoopGroup group) {
this.server.getConfiguration().getConnectTimeout())
.group(group == null ? this.workerGroup : group)
.resolver(this.resolver.asGroup());
if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(EpollChannelOption.TCP_FASTOPEN_CONNECT, true);
if (transportType != TransportType.NIO && server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(ChannelOption.TCP_FASTOPEN_CONNECT, true);
}
return bootstrap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
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;

Expand All @@ -43,6 +48,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,
Expand Down Expand Up @@ -89,6 +98,10 @@ public static TransportType bestType() {
return NIO;
}

if (Boolean.getBoolean("velocity.enable-iouring") && IOUring.isAvailable()) {
return IO_URING;
}

if (Epoll.isAvailable()) {
return EPOLL;
}
Expand Down

0 comments on commit d864a00

Please sign in to comment.