-
Notifications
You must be signed in to change notification settings - Fork 959
Netty 4.2 upgrade + IO_URING support #6021
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,28 +14,25 @@ | |
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.activemq.artemis.core.remoting.impl.netty; | ||
| package org.apache.activemq.artemis.utils; | ||
|
|
||
| import io.netty.channel.epoll.Epoll; | ||
| import io.netty.channel.kqueue.KQueue; | ||
| import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; | ||
| import org.apache.activemq.artemis.utils.Env; | ||
| import org.apache.activemq.artemis.logs.ActiveMQUtilLogger; | ||
|
|
||
| /** | ||
| * This class will check for Epoll or KQueue is available, and return false in case of NoClassDefFoundError it could be | ||
| * improved to check for other cases eventually. | ||
| * This class will check if certain dependencies are available, and return false in case of NoClassDefFoundError | ||
| */ | ||
| public class CheckDependencies { | ||
|
|
||
| public static final boolean isEpollAvailable() { | ||
| try { | ||
| return Env.isLinuxOs() && Epoll.isAvailable(); | ||
| } catch (NoClassDefFoundError noClassDefFoundError) { | ||
| ActiveMQClientLogger.LOGGER.unableToCheckEpollAvailabilitynoClass(); | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckEpollAvailabilityNoClass(); | ||
| return false; | ||
| } catch (Throwable e) { | ||
| ActiveMQClientLogger.LOGGER.unableToCheckEpollAvailability(e); | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckEpollAvailability(e); | ||
| return false; | ||
| } | ||
| } | ||
|
|
@@ -44,10 +41,22 @@ public static final boolean isKQueueAvailable() { | |
| try { | ||
| return Env.isMacOs() && KQueue.isAvailable(); | ||
| } catch (NoClassDefFoundError noClassDefFoundError) { | ||
| ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailabilityNoClass(); | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckKQueueAvailabilityNoClass(); | ||
| return false; | ||
| } catch (Throwable e) { | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckKQueueAvailability(e); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public static final boolean isIoUringAvailable() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added via netty/netty#15785 a way to verify the status of the different optimizations made by io_uring on the OS - you can use it for reporting/debugging 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was about to use it, but I see now that it's so recent that it's not in a release yet. 😆 |
||
| try { | ||
| return Env.isLinuxOs() && NettyIoUringSupport.isAvailable(); | ||
| } catch (NoClassDefFoundError noClassDefFoundError) { | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckIoUringAvailabilityNoClass(); | ||
| return false; | ||
| } catch (Throwable e) { | ||
| ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailability(e); | ||
| ActiveMQUtilLogger.LOGGER.unableToCheckIoUringAvailability(e); | ||
| return false; | ||
| } | ||
| } | ||
|
jbertram marked this conversation as resolved.
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.activemq.artemis.utils; | ||
|
|
||
| import io.netty.channel.Channel; | ||
| import io.netty.channel.IoHandlerFactory; | ||
| import io.netty.channel.ServerChannel; | ||
| import io.netty.channel.uring.IoUring; | ||
| import io.netty.channel.uring.IoUringIoHandler; | ||
| import io.netty.channel.uring.IoUringServerSocketChannel; | ||
| import io.netty.channel.uring.IoUringSocketChannel; | ||
|
|
||
| public final class NettyIoUringSupport { | ||
|
|
||
| public static boolean isAvailable() { | ||
| return IoUring.isAvailable(); | ||
| } | ||
|
|
||
| public static IoHandlerFactory newHandlerFactory() { | ||
| return IoUringIoHandler.newFactory(); | ||
| } | ||
|
|
||
| public static Class<? extends Channel> socketChannelClass() { | ||
| return IoUringSocketChannel.class; | ||
| } | ||
|
|
||
| public static Class<? extends ServerChannel> serverSocketChannelClass() { | ||
| return IoUringServerSocketChannel.class; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.activemq.artemis.utils; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Sanity checks for {@link NettyIoUringSupport}, the single class that references the Netty io_uring transport types. | ||
| * The io_uring classes are on this module's (optional) test classpath, so the class-level assertions below always run; | ||
| * the native-availability assertion is guarded because it needs a supported Linux platform with the native lib loaded. | ||
| */ | ||
| public class NettyIoUringSupportTest { | ||
|
|
||
| @Test | ||
| public void testChannelClassesAreIoUringTypes() { | ||
| assertEquals("io.netty.channel.uring.IoUringSocketChannel", NettyIoUringSupport.socketChannelClass().getName()); | ||
| assertEquals("io.netty.channel.uring.IoUringServerSocketChannel", NettyIoUringSupport.serverSocketChannelClass().getName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAvailabilityCheckDoesNotThrow() { | ||
| // this must always return cleanly (true or false); it must never propagate an exception, since callers rely on it | ||
| // as the gate before touching any io_uring type | ||
| boolean available = CheckDependencies.isIoUringAvailable(); | ||
|
|
||
| // when Env reports a non-Linux platform io_uring can never be considered available | ||
| if (!Env.isLinuxOs()) { | ||
| assertEquals(false, available); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testHandlerFactoryWhenAvailable() { | ||
| assumeTrue(CheckDependencies.isIoUringAvailable()); | ||
|
|
||
| // on a platform where io_uring is available the isolated factory/channel accessors must produce usable objects | ||
| assertNotNull(NettyIoUringSupport.newHandlerFactory()); | ||
| assertNotNull(NettyIoUringSupport.socketChannelClass()); | ||
| assertNotNull(NettyIoUringSupport.serverSocketChannelClass()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least its the case that --enable-native-access was already in JDK17 (as the initial FFM in 17 was an incubator addition there) so hopefully that means it works on all versions of JDK17+ as opposed to just post-GA backport releases, save us doing any checking.