Skip to content

Commit

Permalink
improve ractor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Mar 26, 2022
1 parent e7c4e02 commit 704c79d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ results = Parallel.map(['a','b','c']) do |one_letter|
end

# 3 Processes -> finished after 1 run
results = Parallel.map(['a','b','c'], in_processes: 3) { |one_letter| ... }
results = Parallel.map(['a','b','c'], in_processes: 3) { |one_letter| SomeClass.expensive_calculation(one_letter) }

# 3 Threads -> finished after 1 run
results = Parallel.map(['a','b','c'], in_threads: 3) { |one_letter| ... }
results = Parallel.map(['a','b','c'], in_threads: 3) { |one_letter| SomeClass.expensive_calculation(one_letter) }

# 3 Ractors -> finished after 1 run
results = Parallel.map(['a','b','c'], in_ractors: 3, ractor: [SomeClass, :expensive_calculation])
Expand Down Expand Up @@ -73,11 +73,12 @@ Processes/Threads are workers, they grab the next piece of work when they finish
### Ractors
- Ruby 3.0+ only
- Speedup for blocking operations
- Variables cannot be shared/modified
- No extra memory used
- Very fast to spawn
- Experimental and unstable
- `start` and `finish` hooks are called on main thread
- Variables must be passed in `Parallel.map([1,2,3].map { |i| [i, ARGV, local_var] }, ...`
- use `Ractor.make_shareable` to pass in global objects

### ActiveRecord

Expand Down

0 comments on commit 704c79d

Please sign in to comment.