-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Experiment with fully virtual VirtualThreadPool #11501
Conversation
Virtual threads are used for all threading.
This will also need #11504 |
If a selector thread is virtual, then it's pinned when it is waiting in It is difficult to show with From
From the
|
By default, parallelism=#cores and maxPoolSize=256 (see This means that if we have 8 cores and 8 selectors, we would be completely pinned, if not that FJP can "overshoot" and create other platform threads, up to 256 total. Setting The default idle timeout for the virtual thread FJP scheduler is 30 seconds, so they stay around for a while. The option of only using virtual threads starts to feel in the camp of "magic", as in you think you know how the system works, but not really, until you know the details above. |
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/VirtualThreads.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
We should test this change with the perf profiler but #11513 should be fixed first. |
@sbordet @lorban because of pinning, I doubt this is a viable mode to run it.... but it would still be interesting to include this branch benchmarks just to see what a fully virtual server would run like. This would remove the overheads of both QTP and RTE, but with the risk of parallel slowdown. It might still be a fast (if somewhat risky) mode to run in? |
Considering pinning, I think the current virtual thread mode is safe because we force reserved threads to 0, thus we will never tryExecute a producer task, so the producer should never be virtual. We only use virtual threads to consume BLOCKING tasks, which should not be selectors.... but may be other code that pins the cores, but that should not be us at least. |
…tty-12.0.x/fullyVirtual
@gregw keep it! 😄 Various comments:
@Override
public void dump(Appendable out, String indent) throws IOException
{
dumpObjects(out, indent, new DumpableCollection("virtual threads", _threads.stream().map(t -> new DumpableCollection(t.toString(), List.of(t.getStackTrace()))).toList()));
} to get state & carrier information, and stack frames even of parked virtual threads. QueuedThreadPool qtp = new QueuedThreadPool();
qtp.setVirtualThreadExecutor(new TrackingVirtualExecutor(Executors.newThreadPerTaskExecutor()));
|
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.
Just the virtual thread tracking capabilities are a must-have.
The rest needs cleanup IMHO, but let's continue on this PR.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/VirtualThreads.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
…tty-12.0.x/fullyVirtual
<Call class="org.slf4j.LoggerFactory" name="getLogger"> | ||
<Arg>org.eclipse.jetty</Arg> | ||
<Call name="info"> | ||
<Arg>All Virtual threads are enabled.</Arg> |
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.
Should be more clear as in "Virtual threads enabled, using only virtual threads".
Also the file name should replace "-all-" with "-full-" or "-only-".
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.
I prefer "all". "full" is confusing when pools are involved. What does it mean to have a full non pooling pool? "Only" is ok, but it is just as easy to say "the threads used are all virtual", as it is to say "the threads used are only virtual". However, "only virtual" can be taken as a pejorative (which in this case might be appropriate :), so I prefer "all"
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.
I like jetty-threadpool-only-virtual.xml
jetty-core/jetty-server/src/main/config/modules/threadpool-all-virtual.mod
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TrackingExecutor.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TrackingExecutor.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/thread/VirtualThreadPoolTest.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/config/etc/jetty-threadpool-all-virtual.xml
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TrackingExecutor.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
|
||
try (AutoLock.WithCondition l = _joinLock.lock()) | ||
{ | ||
l.signalAll(); |
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.
l.signal()
seems enough here.
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.
ya'd think! But the join test fails with just signal, I assume because multiple threads can join and wait.
@sbordet sorry I missed a few comments. I'm having troubling making the new intellij review mode update always. I think I have got them all now. |
<Call class="org.slf4j.LoggerFactory" name="getLogger"> | ||
<Arg>org.eclipse.jetty</Arg> | ||
<Call name="info"> | ||
<Arg>Virtual threads enabled. Using virtual threads for all Jetty tasks.</Arg> |
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.
I'd remove "Jetty" here; it is redundant and feels like "only the tasks of the Jetty implementation, so not those of the application".
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.
@sbordet I don't agree. We frequently have issues with users that use a mix of scheduling mechanisms. They might have an asynchronous Jetty Handler that uses some 3rd party async library that ends up using platform threads for its callback, then end up calling Jetty callbacks. It is important to be clear that we are not making all threads in the JVM virtual, just the ones that we dispatch.
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.
@gregw this is the VirtualThreadPool
and "all tasks" refers to the ones submitted to this pool.
There is no need to say "Jetty", it's just the task submitted to this pool.
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.
A server uses a platform thread pool, but have a proxy web application using HttpClient
that uses VirtualThreadPool
and now we have "all Jetty tasks" but which ones, the client's or the server's?
Perhaps let's add "Virtual thread available. Using virtual threads for all tasks submitted to VirtualThreadPool@1234."
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.
I still don't like that, as it is unclear what tasks are submitted to the VTP. It is kind of saying the obvious that the VTP will use virtual threads. We need to make the distinction between using threads for tasks calling the application vs tasks for all jetty tasks. I think the current text does that OK.
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.
@gregw I don't like it because there is no definition of what a "Jetty task" is, and I don't think we want to define that as it won't be useful to users.
We just need to make a difference between: everything is run by a virtual thread, or only web application code, so specifying "Jetty" is redundant because all tasks will be run by virtual threads, not only the "Jetty" tasks.
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.
OK, but you will get a great big "I told you so" the first time we get somebody confused that they have enabled this module, but that there are platform threads calling jetty callbacks and doing jetty things.
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java
Outdated
Show resolved
Hide resolved
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.
See comment.
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.
Generally I'm good with this.
Just some naming niggles, but @sbordet is on the same page as I am there.
Perhaps this should be done for Jetty 12.1.0? That would encourage people to update to 12.1.0 as well.
Virtual threads are used for all threading.