Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Oct 18, 2024
1 parent 7af9155 commit 750dc8e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
15 changes: 15 additions & 0 deletions vertx-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@
</classpathDependencyExcludes>
</configuration>
</execution>
<execution>
<id>io_uring</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>io/vertx/it/transport/IoUringTest.java</include>
</includes>
<classpathDependencyExcludes>
<classpathDependencyExclude>io.netty:netty-transport-classes-epoll</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</execution>
<execution>
<id>connect-to-tls-trusted-server</id>
<goals>
Expand Down
15 changes: 11 additions & 4 deletions vertx-core/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,7 @@ Vert.x can run with http://netty.io/wiki/native-transports.html[native transport
{@link examples.CoreExamples#configureNative()}
----

NOTE: preferring native transport will not prevent the application to execute (for example if a JAR is missing).
If your application requires native transport, you need to check {@link io.vertx.core.Vertx#isNativeTransportEnabled()}.
NOTE: preferring native transport will not prevent the application to execute (for example a native dependency might be missing). If your application requires native transport, you need to check {@link io.vertx.core.Vertx#isNativeTransportEnabled()}.

You can also explicitly configure the transport to use:

Expand All @@ -1034,13 +1033,21 @@ You can also explicitly configure the transport to use:

=== Native epoll

Native on Linux gives you extra networking options:

* `SO_REUSEPORT`
* `TCP_QUICKACK`
* `TCP_CORK`
* `TCP_FASTOPEN`
* `TCP_USER_TIMEOUT`

You need to add the following dependency in your classpath:

[source,xml]
----
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-io_uring</artifactId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<!--<version>Should align with netty version that Vert.x uses</version>-->
</dependency>
Expand All @@ -1054,8 +1061,8 @@ You need to add the following dependency in your classpath:
----
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<artifactId>netty-transport-native-io_uring</artifactId>
<!--<version>Should align with netty version that Vert.x uses</version>-->
</dependency>
----
Expand Down
13 changes: 11 additions & 2 deletions vertx-core/src/main/java/io/vertx/core/impl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,35 @@ public class Utils {

private static final boolean isLinux;
private static final boolean isWindows;
private static final boolean isOsx;

static {
isLinux = "linux".equals(PlatformDependent.normalizedOs());
isWindows = PlatformDependent.isWindows();
isOsx = PlatformDependent.isOsx();
}

/**
* @return true, if running on Linux
* @return {@code true}, if running on Linux
*/
public static boolean isLinux() {
return isLinux;
}

/**
* @return true, if running on Windows
* @return {@code true}, if running on Windows
*/
public static boolean isWindows() {
return isWindows;
}

/**
* @return {@code true}, if running on Mac
*/
public static boolean isOsx() {
return isOsx;
}

@SuppressWarnings("unchecked")
public static <E extends Throwable> void throwAsUnchecked(Throwable t) throws E {
throw (E) t;
Expand Down
22 changes: 19 additions & 3 deletions vertx-core/src/main/java/io/vertx/core/transport/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package io.vertx.core.transport;

import io.vertx.core.impl.Utils;
import io.vertx.core.impl.transports.NioTransport;
import io.vertx.core.impl.transports.TransportInternal;
import io.vertx.core.impl.transports.TransportLoader;
Expand Down Expand Up @@ -50,15 +51,30 @@ public interface Transport {
* Return a native transport suitable for the OS
*
* <ul>
* <li>{@link #EPOLL} on Linux</li>
* <li>{@link #EPOLL} or {@link #IO_URING} on Linux</li>
* <li>{@link #KQUEUE} on Mac</li>
* </ul>
*
* @return a native transport, it might return an unavailable transport ({@link Transport#available()}) then {@link Transport#unavailabilityCause()}
* can be used to check the error preventing its usafe, {@code null} can be returned when no native transport can be loaded.
* can be used to check the error preventing its unsafe, {@code null} can be returned when no native transport can be loaded.
*/
static Transport nativeTransport() {
return KQUEUE != null ? KQUEUE : EPOLL;
Transport transport;
if (Utils.isLinux()) {
transport = EPOLL;
if (transport != null) {
if (!transport.available() && IO_URING != null && IO_URING.available()) {
transport = IO_URING;
}
} else {
transport = IO_URING;
}
} else if (Utils.isOsx()) {
transport = KQUEUE;
} else {
transport = null;
}
return transport;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions vertx-core/src/test/java/io/vertx/it/transport/IoUringTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.it.transport;

import io.vertx.core.impl.Utils;
import io.vertx.core.transport.Transport;
import io.vertx.test.core.AsyncTestBase;
import org.junit.Test;

public class IoUringTest extends AsyncTestBase {
@Test
public void testNativeTransportFallback() {
if (Utils.isLinux()) {
Transport nativeTransport = Transport.nativeTransport();
assertEquals("io_uring", nativeTransport.name());
}
}
}

0 comments on commit 750dc8e

Please sign in to comment.