Skip to content

Add Virtual thread Netty NIO transport#6047

Open
franz1981 wants to merge 3 commits intoeclipse-vertx:masterfrom
franz1981:virtual-thread-transport
Open

Add Virtual thread Netty NIO transport#6047
franz1981 wants to merge 3 commits intoeclipse-vertx:masterfrom
franz1981:virtual-thread-transport

Conversation

@franz1981
Copy link
Copy Markdown
Contributor

@franz1981 franz1981 commented Mar 27, 2026

Run Netty NIO event loops as long-running virtual threads instead of platform thread

Run Netty NIO event loops as long-running virtual threads instead of
platform threads. Uses ManualIoEventLoop from Netty 4.2 to manually
drive IO polling and task execution from virtual threads, allowing the
JVM's ForkJoinPool scheduler to multiplex event loops alongside other
virtual threads.

Adds VirtualThreadNioTransport (SPI), Transport.VIRTUAL_THREAD_NIO
(public API), VertxTestBase support, and a VirtualThreadNio Maven
profile to run the full test suite with this transport.
@franz1981 franz1981 marked this pull request as draft March 27, 2026 16:03
@franz1981 franz1981 force-pushed the virtual-thread-transport branch from 14babee to 9f7b8fb Compare March 27, 2026 18:42
@franz1981 franz1981 marked this pull request as ready for review March 27, 2026 18:42
case "io_uring":
transport = Transport.IO_URING;
break;
case "virtual_thread_nio":
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vietj This could be implemented via the SPI in Quarkus straight on too TBH

@cescoffier I still see the value of having the lower level impls in Vertx if Vertx users can benefit of this

If not, I can send a PR to our Vertx 5 Quarkus branch or @jponge could port this too in the quarkus way.

@franz1981
Copy link
Copy Markdown
Contributor Author

The full benefits of this change would have been by allowing workers to be virtual threads.
In the first iteration of this PR I had this, but I want first get feedbacks on this 🙏

@vietj
Copy link
Copy Markdown
Member

vietj commented Mar 28, 2026

I think this rather should be an option of the NIO transport instead of being called a transport itself

@franz1981
Copy link
Copy Markdown
Contributor Author

And do you want me to add a virtual thread worker too. to get the full benefits of this?

@vietj
Copy link
Copy Markdown
Member

vietj commented Mar 29, 2026

worker are not related to transport, so that would be a different contribution

@franz1981
Copy link
Copy Markdown
Contributor Author

@vietj 🙏 nice one, ok I will change the impl at this point and the CI seems happy (as it should be tbh)

Move virtual thread event loop support from a standalone
VirtualThreadNioTransport into a VertxOptions.virtualThreadEventLoops
flag that enables ManualIoEventLoop-based VT event loops on the
existing NIO transport. Native transports (epoll, kqueue, io_uring)
are rejected when this option is set since JNI pins virtual threads.
Use Thread.Builder.OfVirtual.name(prefix, start) to create a
named virtual thread factory directly, removing the hack that
created throwaway platform threads just to steal their name.
@franz1981
Copy link
Copy Markdown
Contributor Author

PTAL @vietj

Consider that NIO cannot be used before JDK 24 (included I think) and no other transport are possible w this

// Not cached for graalvm
private static ThreadFactory virtualThreadFactory(String prefix) {
try {
Class<?> builderClass = ClassLoader.getSystemClassLoader().loadClass("java.lang.Thread$Builder");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vietj better ideas than doing this?

Copy link
Copy Markdown
Member

@vietj vietj Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in vertx 5.1 we will use multi release jar with Java 21, I think it should help.

@vietj
Copy link
Copy Markdown
Member

vietj commented Mar 31, 2026

I would like to understand how much this setting is important for end-user ? is that a user facing solution or just an advanced feature that is currently for evaluation purpose ?

@franz1981
Copy link
Copy Markdown
Contributor Author

I would like to understand how much this setting is important for end-user ?

This is the "only" way to enable users (including Quarkus) to benefit of having a single thread pool (the ForkJoin one) to run Netty and blocking operations fully utilizing the machine capabilities.
I've talked about it in different contexts including https://youtu.be/Oy005l5vHtE

@vietj
Copy link
Copy Markdown
Member

vietj commented Mar 31, 2026

I'm only afraid that the feature is confusing for most users, so I would like to find a way to make it less obvious (e.g. internal kind of things)

@franz1981
Copy link
Copy Markdown
Contributor Author

I'm only afraid that the feature is confusing for most users, so I would like to find a way to make it less obvious (e.g. internal kind of things)

This is a good point, but the same would happen for transports: why a "normal" user should prefer NIO over "native EPOLL", both are epoll, at the end..
So, this lead to the point where these settings are for "nerd"s (in a good way) and suitable to be used knowing what they implies.

In this case, the sole reason why users would like to enable this is if they can use the "blocking" worker of Vertx to be powered by Loom as well, enabling both the internal core of Vertx and the "blocking" calls to actually runs on the same bunch of physical OS platform thread.
That's why I've asked if I had to provide this option together with this PR: without a VirtualThread powered worker poll IDK why users should pick this setting...

@vietj
Copy link
Copy Markdown
Member

vietj commented Apr 2, 2026

I think the option is fine, I just want to find the proper naming for it to avoid create incorrect expectations from users and make it clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants