Skip to content
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

feat: Enhance virtual thread support #1724

Merged
merged 1 commit into from
Jan 22, 2025
Merged

feat: Enhance virtual thread support #1724

merged 1 commit into from
Jan 22, 2025

Conversation

He-Pin
Copy link
Member

@He-Pin He-Pin commented Jan 17, 2025

Motivation:
Enhances the current virtual thread support which can switch the virtual threads' scheduler.

Modification:
Use the method handle to change the scheduler of virtual threads.

  1. when virtualization is on, the forkJoinPool will create a CarrierThread
  2. and then all actors run on a virtual threads.
  3. when virtualization is off, the actors run on the old PekkoForkJoinWorkerThread.

Result:
Virtualization with virtual threads supported.

We have a user case at $Work, where we are pulling data from a blocking API, With this, I think we can then decrease the Threads number.

based on #1734

@He-Pin He-Pin added this to the 1.2.0 milestone Jan 17, 2025
@He-Pin He-Pin requested review from pjfanning, Roiocam, raboof and jrudolph and removed request for pjfanning January 17, 2025 18:56
@He-Pin He-Pin marked this pull request as ready for review January 17, 2025 18:56
@He-Pin He-Pin requested a review from nvollmar January 17, 2025 18:57
# When set to `on` but underlying runtime does not support virtual threads, an Exception will throw.
# Virtualize this dispatcher as a virtual-thread-executor
# Valid values are: `on`, `off`
virtualize = off
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

behind an option

@He-Pin He-Pin force-pushed the loom branch 2 times, most recently from 262b627 to fc2f4d7 Compare January 17, 2025 19:01
project/JdkOptions.scala Outdated Show resolved Hide resolved
@He-Pin
Copy link
Member Author

He-Pin commented Jan 17, 2025

case ThreadPoolConfig is nowhere.

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be written using MethodHandles. #1724 (comment)

@He-Pin

This comment was marked as outdated.

@He-Pin He-Pin marked this pull request as draft January 17, 2025 23:24
for (_ <- 1 to 1000) {
actor ! "ping"
expectMsgPF() { case name: String =>
name should include("ForkJoinPoolVirtualThreadSpec-virtual.task-dispatcher-virtual-thread-")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it run on a virtual thread, and virtual thread is running on a CarrierThread

@He-Pin He-Pin force-pushed the loom branch 3 times, most recently from 75bc885 to c5fa25a Compare January 21, 2025 08:03
Copy link
Member

@Roiocam Roiocam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no objections to this.

@@ -86,15 +87,28 @@ class ForkJoinExecutorConfigurator(config: Config, prerequisites: DispatcherPrer
}

class ForkJoinExecutorServiceFactory(
val id: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used in createExecutorServiceFactory, some lines below.

@He-Pin
Copy link
Member Author

He-Pin commented Jan 21, 2025

@Roiocam I have addressed your feedback

Copy link
Contributor

@nvollmar nvollmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin He-Pin merged commit 2469f72 into apache:main Jan 22, 2025
9 checks passed
@He-Pin He-Pin deleted the loom branch January 22, 2025 19:55
@He-Pin
Copy link
Member Author

He-Pin commented Jan 22, 2025

Thanks for review.

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.

4 participants