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

ractors #317

Merged
merged 1 commit into from
Mar 21, 2022
Merged

ractors #317

merged 1 commit into from
Mar 21, 2022

Conversation

grosser
Copy link
Owner

@grosser grosser commented Mar 9, 2022

  • in_ractors kinda works
  • need to fix map/each etc
  • need to add tests (exclude from ruby <3)

see gotchas from #298

@grosser grosser changed the title WIP ractors ractors Mar 21, 2022
@grosser grosser merged commit 63a6c02 into master Mar 21, 2022
@grosser grosser deleted the grosser/ractor branch March 21, 2022 01:22
@enumag
Copy link
Contributor

enumag commented Mar 25, 2022

Hello, is there some documentation for the ractors feature? In readme you have just this:

results = Parallel.map(['a','b','c'], in_ractors: 3, ractor: [SomeClass, :expensive_calculation])

Which is a bit confusing:

  • What is that ractor: [SomeClass, :expensive_calculation]? Is expensive_calculation a method name on SomeClass or something else?
  • Is there a way to propagate global variables into the ractor? Or is it done automatically?
  • If not does the ractor at least get the ARGV array of the original process?
  • Can I instead of in_ractors: 3 say "use as many ractors as possible for the current hardware" (such as the total amount of CPU cores)?

@grosser
Copy link
Owner Author

grosser commented Mar 25, 2022

  • yes
  • ractors cannot use global variables
  • ractors cannot use ARGV
  • no, either make a PR or use in_ractors: Etc.nprocessors / Parallel.physical_processor_count

@enumag
Copy link
Contributor

enumag commented Mar 25, 2022

Is there a way to pass some additional parameters to the ractor? When I use the Parallel.map call the SomeClass, :expensive_calculation method will receive one of the items from the array as parameter. But of course I need to pass some other values (same for all ractors). How can I do that?

@grosser
Copy link
Owner Author

grosser commented Mar 25, 2022

actual = [1,2,3]
input = actual.map { |x| [x, ARGV, $whatever] }
Parallel.map input, ...

if it still complains then wrap the object in Ractor.make_shareable

@enumag
Copy link
Contributor

enumag commented Mar 25, 2022

Not very nice API in my opinion but should do the job. Thanks!

@grosser
Copy link
Owner Author

grosser commented Mar 25, 2022

yeah, best I could do, complain to the Ractor implementors :D

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.

None yet

2 participants