r/ruby • u/Edthal01 • 2d ago
Question GVL and concurrent programming
Ruby cannot perform real concurrent processing on multicore microprocessors without using ractors because of the GVL. It will only simulate multiple simultaneous processes with threads, queues, mutexes, etc. in a single processor core, no true parallel processing. How does this limitation affect true parallel programming in Ruby, that is, how much more complicated is it in producing true multicore parallel programming? I am still working on learning Ruby and this is part of my self-inflicted learning process in parallel with Huw Collingworth Book of Ruby.
View all comments
2
u/azimux 2d ago
Hey hey!
There's plenty of options for concurrency. If you need true concurrency for intense CPU-bound work, one option is separate processes if using CRuby. You could also use JRuby which doesn't have the GIL. Or you could use ractors in CRuby though they are experimental.
If what you're doing is heavily IO-bound (like database reads/writes) and not heavily CPU-bound (like in-memory number crunching) then really any concurrency option will work just fine in CRuby (separate processes, ractors, threads, fiber schedulers, or fibers.)
Most places I've worked when we had intense CPU-bound work to do in Ruby, which is extremely rare, then typically we've either used separate processes or even preemptively computed the results if the problem allows it.
At home, for the very rare cases where I did have true CPU-bound work to do, I've either used separate processes or used JRuby.
In short, I don't find concurrency that hard in Ruby though if I needed true parallelism in a seriously resource-constrained environment, then Ruby might not be the most natural choice compared to something with that as a design goal, depending.