Ractors: Multi-Core Parallel Processing Comes to Ruby 3
Ractors: Multi-Core Parallel Processing Comes to Ruby 3
For the longest time, I’ve wanted to be able to do a very simple thing in Ruby.
I’ve wanted to be able to run a block of expensive code multiple times in parallel and see all my CPU cores light up. ✨
This was very hard to do before! While Ruby does support multi-threaded code, only one thread at a time can be actively executing instructions (due to the Global Interpreter Lock, or GIL). That’s fine for apps that are often waiting on external I/O and so forth, but it doesn’t help you much if all your app is primarily concerned with is internal data processing. Historically, the only way you could truly achieve async parallelism in Ruby would be to fork multiple processes or schedule background jobs.
Until now.
Welcome to Ractor, a brand-new method of running async code in Ruby 3.
I hope you enjoy today's article!
-Jared