Kaynağa Gözat

update netty and add io_uring support (#6164)

* use heap buffers for the plaintext response

* remove unnecessary call to fireChannelRead()

* update netty and add io_uring support

* pick netty deps

Co-authored-by: Luis Neves <[email protected]>
Luis Neves 4 yıl önce
ebeveyn
işleme
3bca51032a

+ 12 - 3
frameworks/Java/netty/pom.xml

@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
 	<modelVersion>4.0.0</modelVersion>
 
@@ -9,7 +11,7 @@
 	<properties>
 		<maven.compiler.source>11</maven.compiler.source>
 		<maven.compiler.target>11</maven.compiler.target>
-		<netty.version>4.1.36.Final</netty.version>
+		<netty.version>4.1.54.Final</netty.version>
 	</properties>
 
 	<packaging>jar</packaging>
@@ -36,6 +38,13 @@
 			<classifier>osx-x86_64</classifier>
 		</dependency>
 
+		<dependency>
+			<groupId>io.netty.incubator</groupId>
+			<artifactId>netty-incubator-transport-native-io_uring</artifactId>
+			<version>0.0.1.Final</version>
+			<classifier>linux-x86_64</classifier>
+		</dependency>
+
 		<dependency>
 			<groupId>com.jsoniter</groupId>
 			<artifactId>jsoniter</artifactId>
@@ -45,7 +54,7 @@
 		<dependency>
 			<groupId>org.javassist</groupId>
 			<artifactId>javassist</artifactId>
-			<version>3.25.0-GA</version>
+			<version>3.27.0-GA</version>
 		</dependency>
 
 	</dependencies>

+ 14 - 2
frameworks/Java/netty/src/main/java/hello/HelloWebServer.java

@@ -15,6 +15,10 @@ import io.netty.channel.kqueue.KQueue;
 import io.netty.channel.kqueue.KQueueServerSocketChannel;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.incubator.channel.uring.IOUring;
+import io.netty.incubator.channel.uring.IOUringChannelOption;
+import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
+import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
 import io.netty.util.ResourceLeakDetector;
 import io.netty.util.ResourceLeakDetector.Level;
 
@@ -32,8 +36,10 @@ public class HelloWebServer {
 
 	public void run() throws Exception {
 		// Configure the server.
-
-		if (Epoll.isAvailable()) {
+		if (IOUring.isAvailable()) {
+			doRun(new IOUringEventLoopGroup(), IOUringServerSocketChannel.class, IoMultiplexer.IO_URING);
+		} else
+			if (Epoll.isAvailable()) {
 			doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class, IoMultiplexer.EPOLL);
 		} else if (KQueue.isAvailable()) {
 			doRun(new EpollEventLoopGroup(), KQueueServerSocketChannel.class, IoMultiplexer.KQUEUE);
@@ -45,6 +51,8 @@ public class HelloWebServer {
 	private void doRun(EventLoopGroup loupGroup, Class<? extends ServerChannel> serverChannelClass, IoMultiplexer multiplexer) throws InterruptedException {
 		try {
 			InetSocketAddress inet = new InetSocketAddress(port);
+			
+			System.out.printf("Using %s IoMultiplexer%n", multiplexer);
 
 			ServerBootstrap b = new ServerBootstrap();
 
@@ -52,6 +60,10 @@ public class HelloWebServer {
 				b.option(EpollChannelOption.SO_REUSEPORT, true);
 			}
 			
+			if (multiplexer == IoMultiplexer.IO_URING) {
+				b.option(IOUringChannelOption.SO_REUSEPORT, true);
+			}
+			
 			b.option(ChannelOption.SO_BACKLOG, 8192);
 			b.option(ChannelOption.SO_REUSEADDR, true);
 			b.group(loupGroup).channel(serverChannelClass).childHandler(new HelloServerInitializer(loupGroup.next()));

+ 1 - 1
frameworks/Java/netty/src/main/java/hello/IoMultiplexer.java

@@ -1,5 +1,5 @@
 package hello;
 
 public enum IoMultiplexer {
-	EPOLL, KQUEUE, JDK
+	EPOLL, KQUEUE, JDK, IO_URING
 }