diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 0921656f7f3..7dadfa6f97a 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -120,6 +120,7 @@ 8.0.22 5.12.0.Final 4.1.63.Final + 0.0.8.Final 2.3.0 21.3.0.0 19.3.0.0 @@ -1274,6 +1275,12 @@ ${version.lib.netty} osx-x86_64 + + io.netty.incubator + netty-incubator-transport-native-io_uring + ${version.lib.netty-io_uring} + linux-x86_64 + io.netty netty-common diff --git a/webserver/transport/netty/iouring/pom.xml b/webserver/transport/netty/iouring/pom.xml new file mode 100644 index 00000000000..522f1374ac4 --- /dev/null +++ b/webserver/transport/netty/iouring/pom.xml @@ -0,0 +1,45 @@ + + + + + 4.0.0 + + io.helidon.webserver.transport.netty + helidon-webserver-transport-netty-project + 2.4.0-SNAPSHOT + + helidon-webserver-transport-netty-iouring + Helidon WebServer Transport Netty io_uring + + + + io.helidon.webserver + helidon-webserver + + + io.netty.incubator + netty-incubator-transport-native-io_uring + linux-x86_64 + + + + + diff --git a/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/IOUringTransport.java b/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/IOUringTransport.java new file mode 100644 index 00000000000..e6a42888088 --- /dev/null +++ b/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/IOUringTransport.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.webserver.transport.netty.iouring; + +import java.util.Optional; + +import io.helidon.webserver.ServerConfiguration; +import io.helidon.webserver.Transport; +import io.helidon.webserver.WebServer; + +import io.netty.channel.ChannelFactory; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.ServerChannel; +import io.netty.incubator.channel.uring.IOUring; +import io.netty.incubator.channel.uring.IOUringEventLoopGroup; +import io.netty.incubator.channel.uring.IOUringServerSocketChannel; + + +/** + * A {@link Transport} implementation based upon Netty's iouring-based native transport. + * + *

This {@link Transport} implementation is currently experimental + * and its API and implementation are subject to change.

+ */ +public final class IOUringTransport implements Transport { + + /** + * Returns {@code true} when {@link IOUring#isAvailable()} returns + * {@code true} and {@code false} otherwise. + * + * @return {@code true} when {@link IOUring#isAvailable()} returns + * {@code true}; {@code false} otherwise + */ + @Override + public boolean isAvailableFor(WebServer webServer) { + return IOUring.isAvailable(); + } + + /** + * Returns an artifact corresponding to the supplied artifact + * coordinates, if one is available. + * + *

Specifically, this method will return a non-{@linkplain + * Optional#isEmpty() empty Optional} only if one of the + * following conditions is true:

+ * + * + * + * @param artifactType a {@link Class} indicating the kind of + * artifact to be returned; must not be {@code null}; may usefully + * only be a subtype of either {@link EventLoopGroup} or + * {@linkplain ChannelFactory ChannelFactory<? extends + * ServerChannel>} + * + * @param artifactName a {@link String} indicating which of + * possibly several artifacts of the same kind to be returned; + * must not be {@code null} + * + * @param config the {@link ServerConfiguration} in effect; must + * not be {@code null} + * + * @return an {@link Optional}, which may be {@linkplain + * Optional#isEmpty() empty} but which will never be {@code null} + * + * @exception NullPointerException if any argument is {@code null} + * + * @see IOUring + * + * @see IOUringEventLoopGroup + * + * @see IOUringServerSocketChannel + */ + @Override + @SuppressWarnings("unchecked") + public Optional createTransportArtifact(Class artifactType, + String artifactName, + ServerConfiguration config) { + if (EventLoopGroup.class.isAssignableFrom(artifactType)) { + switch (artifactName) { + case "bossGroup": + return Optional.of((T) new IOUringEventLoopGroup(config.sockets().size())); + case "workerGroup": + return Optional.of((T) new IOUringEventLoopGroup(Math.max(0, config.workersCount()))); + default: + return Optional.empty(); + } + } else if (ChannelFactory.class.isAssignableFrom(artifactType)) { + switch (artifactName) { + case "serverChannelFactory": + ChannelFactory cf = IOUringServerSocketChannel::new; + return Optional.of((T) cf); + default: + return Optional.empty(); + } + } else { + return Optional.empty(); + } + } + +} diff --git a/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/package-info.java b/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/package-info.java new file mode 100644 index 00000000000..fc59a40f770 --- /dev/null +++ b/webserver/transport/netty/iouring/src/main/java/io/helidon/webserver/transport/netty/iouring/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Netty io_uring Transport implementation. + */ +package io.helidon.webserver.transport.netty.iouring; diff --git a/webserver/transport/netty/iouring/src/main/java/module-info.java b/webserver/transport/netty/iouring/src/main/java/module-info.java new file mode 100644 index 00000000000..53578c1970b --- /dev/null +++ b/webserver/transport/netty/iouring/src/main/java/module-info.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Netty IOURING transport. + */ +module io.helidon.webserver.transport.netty.iouring { + requires io.helidon.webserver; + + requires io.netty.transport; + + requires io.netty.incubator.transport.io_uring; + + exports io.helidon.webserver.transport.netty.iouring; +} diff --git a/webserver/transport/netty/pom.xml b/webserver/transport/netty/pom.xml index 8f274e4a0f0..2890af58f94 100644 --- a/webserver/transport/netty/pom.xml +++ b/webserver/transport/netty/pom.xml @@ -33,5 +33,6 @@ epoll + iouring