-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Parallelism limitation of 100 VirtualThread in Flux #3857
Comments
Hey @expe-elenigen! Thank you for the report. This VT-based You can change that default with the I will investigate the other effects you are seeing but please consider the above config for the time being. |
This aspect is explained in my above comment.
The Virtual Threads are not reused, they use a thread-per-task model with in-order processing within a
Absolutely correct. I will push a fix soon. |
This change prevents the same `BoundedElasticThreadPerTaskScheduler` being picked up when the maximum number of Virtual Threads are already being executed in parallel. The consequence of improper busyness accounting was that tasks were executed sequentially instead of being run in parallel because the same `Worker` was being picked by operators. Resolves #3857
Expected Behavior
With Java 21 VirtualThread, I was expecting to be able to run a huge number of virtual threads in parallel, since they are much lighter to handle. I tried to run a Flux configured with a schedule which is a
Schedulers.boundedElastic()
while enabling the virtual threads:-Dreactor.schedulers.defaultBoundedElasticOnVirtualThreads=true
.The test is simple, in a loop, I run simple Thread sleep of 1 sec and at first it worked, if I picked a value 100 virtual threads, I can see them from
loomBoundedElastic-1
toloomBoundedElastic-100
are executed and the total time elapsed is ~1 sec but if I double this number to 200, I would still expect to see ~1 sec.Actual Behavior
With 200, I see a different pattern where the first 100 virtual threads are executed with the same ~1 sec, but then the remaining 100 are executed in ~ 100 sec for a total of 101542 ms.
Steps to Reproduce
Here's the code:
Logs TOTAL = 200
Logs TOTAL = 100
Possible Solution
I didn't see anywhere mentioning a limitation of 100 virtual threads and I'm curious also if the threads are supposed to be reused or they are simply disposable? I was also thinking, if there's a cap of 100 threads, once the first batch is processed, the second 100 tasks should be done within 1 sec, so a total of ~2 sec.
Your Environment
MacBook Pro M1
netty
, ...): N/Ajava -version
): OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)uname -a
): 23.5.0 Darwin Kernel Version 23.5.0The text was updated successfully, but these errors were encountered: