-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experiment with fully virtual VirtualThreadPool (#11501)
Virtual threads are used for all threading.
- Loading branch information
Showing
11 changed files
with
627 additions
and
61 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
jetty-core/jetty-server/src/main/config/etc/jetty-threadpool-all-virtual.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure> | ||
<New id="threadPool" class="org.eclipse.jetty.util.thread.VirtualThreadPool"> | ||
<Set name="name" property="jetty.threadPool.namePrefix" /> | ||
</New> | ||
|
||
<Call class="org.slf4j.LoggerFactory" name="getLogger"> | ||
<Arg>org.eclipse.jetty</Arg> | ||
<Call name="info"> | ||
<Arg>Virtual threads enabled. Using virtual threads for all tasks.</Arg> | ||
</Call> | ||
</Call> | ||
</Configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
jetty-core/jetty-server/src/main/config/modules/threadpool-all-virtual.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[description] | ||
Enables and configures the Server ThreadPool with support for virtual threads to be used for all threads. | ||
There is some risk of CPU pinning with this configuration. Only supported in Java 21 or later. | ||
|
||
[depends] | ||
logging | ||
|
||
[provides] | ||
threadpool | ||
|
||
[xml] | ||
etc/jetty-threadpool-all-virtual.xml | ||
|
||
[ini-template] | ||
# tag::documentation[] | ||
## Platform threads name prefix. | ||
#jetty.threadPool.namePrefix=vtp<hashCode> | ||
|
||
# end::documentation[] |
3 changes: 2 additions & 1 deletion
3
jetty-core/jetty-server/src/main/config/modules/threadpool-virtual.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TrackingExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util.thread; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.Executor; | ||
|
||
import org.eclipse.jetty.util.annotation.ManagedAttribute; | ||
import org.eclipse.jetty.util.annotation.ManagedObject; | ||
import org.eclipse.jetty.util.component.Dumpable; | ||
|
||
@ManagedObject("Tracking Executor wrapper") | ||
public class TrackingExecutor implements Executor, Dumpable | ||
{ | ||
private final Executor _threadFactoryExecutor; | ||
private final Set<Thread> _threads = ConcurrentHashMap.newKeySet(); | ||
private boolean _detailed; | ||
|
||
public TrackingExecutor(Executor executor, boolean detailed) | ||
{ | ||
_threadFactoryExecutor = executor; | ||
_detailed = detailed; | ||
} | ||
|
||
@Override | ||
public void execute(Runnable task) | ||
{ | ||
_threadFactoryExecutor.execute(() -> | ||
{ | ||
Thread thread = Thread.currentThread(); | ||
try | ||
{ | ||
_threads.add(thread); | ||
task.run(); | ||
} | ||
finally | ||
{ | ||
_threads.remove(thread); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void dump(Appendable out, String indent) throws IOException | ||
{ | ||
Object[] threads = _threads.stream().map(DumpableThread::new).toArray(); | ||
Dumpable.dumpObjects(out, indent, _threadFactoryExecutor.toString() + " size=" + threads.length, threads); | ||
} | ||
|
||
public void setDetailedDump(boolean detailedDump) | ||
{ | ||
_detailed = detailedDump; | ||
} | ||
|
||
@ManagedAttribute("reports additional details in the dump") | ||
public boolean isDetailedDump() | ||
{ | ||
return _detailed; | ||
} | ||
|
||
public int size() | ||
{ | ||
return _threads.size(); | ||
} | ||
|
||
private class DumpableThread implements Dumpable | ||
{ | ||
private final Thread _thread; | ||
|
||
private DumpableThread(Thread thread) | ||
{ | ||
_thread = thread; | ||
} | ||
|
||
@Override | ||
public void dump(Appendable out, String indent) throws IOException | ||
{ | ||
if (_detailed) | ||
{ | ||
Object[] stack = _thread.getStackTrace(); | ||
Dumpable.dumpObjects(out, indent, _thread.toString(), stack); | ||
} | ||
else | ||
{ | ||
Dumpable.dumpObject(out, _thread); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.