Skip to content

Require explicit config to use io_uring transport #3234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,16 @@ Native transports are available with:
classifier `linux-x86_64`. Note that this transport is still
experimental.

Note that both epoll and io_uring transports are supported on Linux. If
you need both libraries to be present—for example if you're using a
different transport for another Netty library—you must resolve this
ambiguity explicitly via one of the following options:
1. Set the system property `io.lettuce.core.iouring=true` to prefer
io_uring for all supported functions. epoll will be used for Unix
domain sockets, which are not supported for io_uring.
2. Set `io.lettuce.core.iouring=false` to completely disable io_uring.
3. Set `io.lettuce.core.epoll=false` to completely disable epoll.

``` xml
<dependency>
<groupId>io.netty.incubator</groupId>
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/io/lettuce/core/resource/IOUringProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.unix.DomainSocketAddress;
import io.netty.incubator.channel.uring.IOUring;
import io.netty.incubator.channel.uring.IOUringChannelOption;
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
Expand All @@ -52,29 +51,33 @@ public class IOUringProvider {

private static final String IOURING_ENABLED_KEY = "io.lettuce.core.iouring";

private static final boolean IOURING_ENABLED = Boolean.parseBoolean(SystemPropertyUtil.get(IOURING_ENABLED_KEY, "true"));
private static final boolean IOURING_ENABLED;

private static final boolean IOURING_AVAILABLE;

private static final EventLoopResources IOURING_RESOURCES;

static {

boolean availability;
boolean libraryPresent;
try {
Class.forName("io.netty.incubator.channel.uring.IOUring");
availability = IOUring.isAvailable();
libraryPresent = true;
} catch (ClassNotFoundException e) {
availability = false;
libraryPresent = false;
}

IOURING_AVAILABLE = availability;
String enabledStr = SystemPropertyUtil.get(IOURING_ENABLED_KEY);
if (libraryPresent && enabledStr == null && EpollProvider.isAvailable()) {
throw new IllegalStateException("Both io_uring and epoll transports are available. " + IOURING_ENABLED_KEY
+ " system property must be set to true or false.");
}
IOURING_ENABLED = enabledStr == null || Boolean.parseBoolean(enabledStr);
IOURING_AVAILABLE = libraryPresent && IOURING_ENABLED;

if (IOURING_AVAILABLE) {
logger.debug("Starting with io_uring library");
IOURING_RESOURCES = new EventLoopResourcesWrapper(IOUringResources.INSTANCE,
IOUringProvider::checkForIOUringLibrary);

} else {
logger.debug("Starting without optional io_uring library");
IOURING_RESOURCES = new EventLoopResourcesWrapper(UnavailableResources.INSTANCE,
Expand Down