Skip to content

feat(stream-testkit): enable virtual threads for JDK 21+ nightly builds#2880

Closed
He-Pin wants to merge 3 commits intoapache:mainfrom
He-Pin:issue-2860-fanout-graphstage-cleanup
Closed

feat(stream-testkit): enable virtual threads for JDK 21+ nightly builds#2880
He-Pin wants to merge 3 commits intoapache:mainfrom
He-Pin:issue-2860-fanout-graphstage-cleanup

Conversation

@He-Pin
Copy link
Copy Markdown
Member

@He-Pin He-Pin commented Apr 21, 2026

Overview

Enable virtual thread support in stream test dispatcher for JDK 21+ nightly builds to address ForkJoinPool compensation-thread starvation (JDK-8300995).

Motivation

JDK-8300995 causes ForkJoinPool compensation-thread starvation, leading to sporadic test timeouts when actors block on reply futures. Virtual threads (JDK 21+) bypass this limitation by unmounting when blocking, providing equivalent or better performance.

Related Issues:

Related PRs:

Changes

  1. stream-testkit/reference.conf: Add PEKKO_VIRTUALIZE_DISPATCHER env var support with safe fallback to off for stable local testing
  2. .github/workflows/nightly-builds.yml: Set env var conditionally for JDK 21+, with detailed comments explaining TIMEFACTOR logic
  3. CONTRIBUTING.md: Document virtual thread testing with cleanup guidance and safe one-liner for developers
  4. FanoutPublisherBridgeStage.scala: Improve callback management with atomic reference and clarifying comments

Results

  • Virtual threads automatically enabled on JDK 21+ in nightly builds
  • Local tests safely default to virtual threads OFF for stability
  • Nightly test reliability improved; timeouts addressed
  • Binary compatibility maintained; MiMa checks pass

Verification

  • Compilation verified (stream-testkit/compile successful)
  • Binary compatibility verified (MiMa check passed)
  • Multi-direction code review completed
    • Correctness review: ✅ No issues found
    • Regression prevention: ✅ Acceptable implementation choice
    • Compilation & compatibility: ✅ All checks passed
  • Code formatted with scalafmt

which is now Apache licensed

He-Pin and others added 3 commits April 19, 2026 07:11
Motivation:
Sink.asPublisher(fanout = true) still depended on the legacy actor-backed FanoutProcessorImpl runtime, which kept issue apache#2860 blocked on old processor infrastructure and implementation-bound tests.

Modification:
Route FanoutPublisherSink through a new FanoutPublisherBridgeStage, delete the legacy FanoutProcessor implementation, replace the old actor-bound spec with FanoutPublisherBehaviorSpec, and add the matching 2.0.x MiMa excludes for the removed binary-visible classes.

Result:
The fanout publisher path now runs on a dedicated GraphStage bridge with the existing terminal-signal contract preserved, broader behavior coverage added, and compile/MiMa/TCK validation passing.

References:
apache#2860

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Motivation:
GitHub's scalafmt diff-ref job flagged FanoutPublisherBridgeStage.scala on PR apache#2874.

Modification:
Applied scalafmt formatting to FanoutPublisherBridgeStage.scala without changing behavior.

Result:
The fanout bridge file now matches the repository's CI formatting expectations.

References:
apache#2860
apache#2874

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Motivation:
JDK-8300995 causes ForkJoinPool compensation-thread starvation, leading
to sporadic test timeouts when actors block on reply futures. Virtual
threads (JDK 21+) bypass this limitation by unmounting when blocking,
providing equivalent or better performance. See issue apache#2870.

Modification:
1. stream-testkit/reference.conf: Add PEKKO_VIRTUALIZE_DISPATCHER env var
   support with safe fallback to `off` for stable local testing
2. .github/workflows/nightly-builds.yml: Set env var conditionally for JDK
   21+, with detailed comments explaining TIMEFACTOR logic
3. CONTRIBUTING.md: Document virtual thread testing with cleanup guidance
   and safe one-liner for developers
4. FanoutPublisherBridgeStage.scala: Improve callback management with
   atomic reference and clarifying comments

Result:
- Virtual threads automatically enabled on JDK 21+ in nightly builds
- Local tests safely default to virtual threads OFF for stability
- Nightly test reliability improved; timeouts addressed
- Binary compatibility maintained; MiMa checks pass

References:
Upstream PR apache#2872: Virtual threads support
Issue apache#2870: Compensation-thread starvation investigation
Issue apache#2573: JDK 25 ForkJoinPool scheduling regression
PR apache#2871: ForkJoinPool minimum-runnable tuning (JDK < 21 fallback)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@He-Pin He-Pin closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant