Stop using named (with counter) VT names due to https://bugs.openjdk.org/browse/JDK-8372410#51223
Stop using named (with counter) VT names due to https://bugs.openjdk.org/browse/JDK-8372410#51223franz1981 wants to merge 3 commits intoquarkusio:mainfrom
Conversation
franz1981
commented
Nov 25, 2025
- Fixes RunOnVirtualThread has some unexpected cost due to the default VT builder #51201
ozangunalp
left a comment
There was a problem hiding this comment.
If we remove the counter we should remove the trailing dash in VirtualThreadsConfig#namePrefix default value. So the default thread name would be quarkus-virtual-thread.
Or we can remove the name call completely and let VTs have default thread names, until the JDK bug is resolved.
This comment has been minimized.
This comment has been minimized.
|
@ozangunalp |
|
I agree let's remove the trailing dash from |
fb2d5ea to
daf2b3e
Compare
|
I saw few failing tests before, let's see if I forgot anything. |
|
What does it bring exactly? It makes so much of a difference that we can’t wait for the JDK fix? |
That's a good point. Setting the config Edit: Like this : https://quarkus.io/guides/virtual-threads#virtual-thread-names |
gastaldi
left a comment
There was a problem hiding this comment.
Don't forget to also change the guide here:
Let me show you... package red.hat.puzzles.loom;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 10, time = 400, timeUnit = TimeUnit.MILLISECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(2)
public class VirtualThreadThreadCreate {
ThreadFactory namingFactory;
ThreadFactory delegatingFactory;
ThreadFactory prefixOnlyFactory;
private String prefix;
@Setup
public void init() {
prefix = "quarkus-virtual-thread-";
namingFactory = Thread.ofVirtual().name(prefix, 0).factory();
var vtFactory = Thread.ofVirtual().factory();
final AtomicLong counter = new AtomicLong();
delegatingFactory = r -> {
Thread t = vtFactory.newThread(r);
t.setName(prefix + counter.getAndIncrement());
return t;
};
prefixOnlyFactory = Thread.ofVirtual().name(prefix).factory();
}
@Benchmark
public Thread createWithNamingFactory() {
return namingFactory.newThread(() -> {
});
}
@Benchmark
public Thread createWithDelegatingFactory() {
return delegatingFactory.newThread(() -> {
});
}
@Benchmark
public Thread createWithPrefixOnlyFactory() {
return prefixOnlyFactory.newThread(() -> {
});
}
}we got: which shows that the version without counter is not only faster but cheaper in term of allocations. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@franz1981 I'm afraid there are several tests that will need to be adapted |
|
Thanks, looking into it |
|
While waiting the status of the tests, I see these options here:
I have to be honest that although I'm usually all in for low risk changes, Loom adoption is still at early stages, and I prefer to not maintaining features which imply a cost on our side and no improvement for the life of users. |
This comment has been minimized.
This comment has been minimized.
|
I like option 1 |
|
+1. Let's go with option 1. |
|
I actually liked the fact that virtual threads have a name with a unique number too. And I would showcase that with some demos in my presentations too 😄 This is quite useful when you are inspecting what is happening and to check where you code is executed. Just build this branch locally and with this change everything that runs on a virtual threads shows as |
This looks more a problem of logging instead, which shouldn't rely on thread names but on thread ids Thread.toString is making use of both informations because the name alone, being just a String, is not expected/enforced to identify uniquely them, whilst the thread id has been implemented to do so @ozangunalp any idea where it happens? |
If we somehow can make the logging output the thread id that would be good I think to be able to correctly identify them. |
This comment has been minimized.
This comment has been minimized.
|
The issue is most users already use the thread name in their logs to identify threads. I think we accept that downside, and can add to the documentation that VTs can still be identified via thread ids. |
Thanks @wjglerum ! I think this is really important feedback - I naively assumed from @franz1981 's comments above about using I agree this would be a substantial set back if existing log formats wouldn't be able to distinguish two different threads - in this case my preference changes, I don't think we can break that - error diagnostics needs to remain useable. I see two options:
|
|
Due to the better and correct usage of thread Ids I would vote for
No idea where loggings happen - any pointer? |
c8900f5 to
2b55888
Compare
|
@ozangunalp @geoand waiting the CI, this was my leftover PR ^^ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c0c432b to
c17aa1e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
PTAL @ozangunalp @geoand
the last error I see :"( but doesn't seem related my changes here no? |
c17aa1e to
a0df980
Compare
Status for workflow
|
Status for workflow
|
|
Can you squash your commits? |
| [source, properties] | ||
| ---- | ||
| quarkus.virtual-threads.name-prefix= | ||
| quarkus.virtual-threads.name-prefix=<your prefix or an empty value> |
There was a problem hiding this comment.
Maybe explain what happens if it's an empty value?
There was a problem hiding this comment.
In theory it is the same for other properties; empty is considered as absent...but if it helps users I can do it for sure 🙏
There was a problem hiding this comment.
Do we really need yet-another-property? What's the value of allowing to configure this?
There was a problem hiding this comment.
It's not a new property; it's what some users asked for because they feel can improve their debugging sessions.
I have clarified at #51223 (comment) what means
There was a problem hiding this comment.
It's not a new property
hum ok then...
