You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/04/18 18:52:37 UTC
[PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
He-Pin opened a new pull request, #2872:
URL: https://github.com/apache/pekko/pull/2872
## Summary
Enables `virtualize = on` in the Pekko stream test dispatcher so that on JDK 21+ each dispatcher task runs in its own virtual thread (Project Loom). This **bypasses** the ForkJoinPool compensation-thread scheduling regression (JDK-8300995) at the root rather than working around it.
> ⚠️ **Depends on #2869** (test stability fixes). Retarget this PR to `main` after #2869 merges.
---
## Root Cause Recap
ForkJoinPool with `asyncMode=FIFO` on JDK 21+ places response tasks at the back of the deque, causing actor reply futures to queue behind unrelated tasks. Compensation threads that should keep worker count stable became more conservative in JDK-8321335 (JDK 21) and have not improved in JDK 25. This manifests as cascading latency spikes in any test with tight actor round-trips (MergeHub, HubSpec, etc.).
## How `virtualize = on` Fixes It
With `virtualize = on`, each dispatcher `Runnable` is scheduled as a virtual thread (JDK 21+ Project Loom). Virtual threads **unmount** their carrier when they block (e.g., awaiting an actor reply), freeing the carrier for other work. The FJP pool's FIFO-ordering starvation cannot happen because:
- There are no blocked workers holding carriers
- Compensation threads are never needed for actor-reply waits
- The FJP pool is used only as a **carrier scheduler**, not to queue Runnables
## Changes
`stream-testkit/src/test/resources/reference.conf`
```hocon
pekko.test.stream-dispatcher {
fork-join-executor {
# Enable virtual threads on JDK 21+. Silently ignored on JDK < 21.
virtualize = on
}
}
```
## Safety Notes
- On JDK < 21: `VirtualThreadSupport.isSupported = false` → flag silently ignored, pool behaves identically to today
- `--add-opens` flags required by Loom are already supplied by `JdkOptions.scala` for JDK 9+
- Mailbox ordering is unaffected (UnboundedMailbox is always FIFO)
- Verified: 48/48 HubSpec tests pass in ~20 seconds on JDK 25 (was 2+ minutes timeout previously)
## Relation to Other PRs
| PR | What it does |
|----|-------------|
| #2869 | Test stability fixes (patience scaling, element counts, TCK timefactor) |
| #2871 | FJP config improvements (LIFO, configurable minimum-runnable, max-pool-size docs) |
| **this PR** | Root-cause fix: virtual threads bypass FJP scheduling entirely |
| #2870 | Tracking issue documenting the JDK-8300995 root cause |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin closed pull request #2872: feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression
URL: https://github.com/apache/pekko/pull/2872
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin closed pull request #2872: feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression
URL: https://github.com/apache/pekko/pull/2872
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2872:
URL: https://github.com/apache/pekko/pull/2872#discussion_r3109707468
##########
stream-testkit/src/test/resources/reference.conf:
##########
@@ -14,6 +14,13 @@ pekko.test.stream-dispatcher {
fork-join-executor {
parallelism-min = 8
parallelism-max = 8
+ # Enable virtual threads on JDK 21+. Virtual threads (Project Loom) bypass the
Review Comment:
Yes, this can be done. we can enable it just for Java 25 and Java 21
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2872:
URL: https://github.com/apache/pekko/pull/2872#discussion_r3109581048
##########
stream-testkit/src/test/resources/reference.conf:
##########
@@ -14,6 +14,13 @@ pekko.test.stream-dispatcher {
fork-join-executor {
parallelism-min = 8
parallelism-max = 8
+ # Enable virtual threads on JDK 21+. Virtual threads (Project Loom) bypass the
Review Comment:
could this be moved to the application.conf file(s) where we might still have test issues - instead of making it a global setting that affects any test that uses the stream-testkit?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2872:
URL: https://github.com/apache/pekko/pull/2872#issuecomment-4287385903
Superseded by PR #2881 which includes enhanced virtual thread support with environment variable conditioning and developer documentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2872:
URL: https://github.com/apache/pekko/pull/2872#issuecomment-4277704587
@pjfanning I want to turn this on in the nightly build for Java 25
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] feat: enable virtualize=on in stream test dispatcher to bypass JDK 21+ FJP scheduling regression [pekko]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2872:
URL: https://github.com/apache/pekko/pull/2872#issuecomment-4274387956
## 🔬 Key Finding & Decision
### What we measured
Enabling `virtualize = on` in the stream test dispatcher produced a dramatic speedup:
| Test suite | Without virtual threads | With virtual threads |
|-----------|------------------------|---------------------|
| HubSpec (48 tests) | 2+ min timeout (3 failures) | **~20 seconds, 48/48 pass** |
Virtual threads completely bypass the ForkJoinPool FIFO-starvation issue (JDK-8300995) because blocked virtual threads **unmount** their carrier, so compensation threads are never needed for actor-reply waits.
### Why we're NOT merging this as a default
The concern is sound: silently switching the stream test dispatcher to virtual threads changes the runtime model — any test that implicitly relies on FJP scheduling behavior (thread affinity, carrier pinning, blocking detection) could produce false positives or mask real issues. Enabling it only in CI for JDK 21+ would be a hidden configuration divergence.
### Recommended path
1. **Opt-in per test config**: teams investigating virtual-thread performance can add `virtualize = on` to their own `reference.conf` override. The support is already present in Pekko v1.2.0+.
2. **Future work**: a dedicated `VirtualThreadDispatcherSpec` that explicitly opts in and asserts virtual-thread behavior is a better way to validate this path without affecting all stream tests. Tracked in #2870.
Closing in favour of documenting in #2870.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org