Skip to content

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 Roiocam, jrudolph, pjfanning and raboof 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
@He-Pin
Copy link
Member Author

He-Pin commented Jan 17, 2025

case ThreadPoolConfig is nowhere.

Copy link
Member

@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
@He-Pin He-Pin force-pushed the loom branch 2 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.

}

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
Member

@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.

@lenguyenthanh
Copy link

@He-Pin do you happen to have any performance comparison between enable virtual threads or not?

@He-Pin
Copy link
Member Author

He-Pin commented Nov 28, 2025

It only help when you are working with some blocking....

@lenguyenthanh
Copy link

got it, thanks!

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.

5 participants