by jbotdev · 4y ago · 0 comments
* Run a bunch of background workers (Sidekiq/Resque), and queue up a job for each item you want processed in parallel.
* Provide relatively granular HTTP APIs, and have your JS frontend call them in parallel with AJAX, instead of having the server handle concurrency.
I think this is just the nature of Ruby being widely used for web apps where performance isn’t a big concern. That said, I’d love to see Ractor catch on, since it’s a pattern built into the language everyone could standardize on.
It's entirely orthogonal concerns. Job queues are for "fire and forget" tasks. Using Sidekiq and co offer tons of advantage over queuing this in a local thread pool / coroutine or similar.
It provides efficient backoff retries, work distribution, durability, backpressure, and a tons of other goodies.
If you were to just queue these things in-process, you may queue more work than your process can handle which may hurt latency.
It also make deploy of web application awkward. If you know jobs are externally queue, you can stop sending traffic to that process and once all in-flight requests are completed you know it's safe to stop the process. If that process may contains queued work, well who knows when it's safe to restart it.
In process concurrency (or parallelism) is useful for other things (e.g. parallel queries to a service), and that's were you use threads / fibers / ractors / async.
My info may be dated, I haven’t kept up with developments in Ruby 3. Is the GIL not going to be a thing any more?
Ruby 1.8 had green threads, 1.9 onwards has native threads, but with a GVL. And 3.2 may have N:M threads.
> Is the GIL not going to be a thing any more?
On paper it's already done in 3.0. What used to be the GVL is now one lock per Ractor. Every object belongs to a Ractor, and the Ractor lock need to be acquired to access the objects, except for mutable objects that can be shared across ractors.
So in practice if you are not spawning any more ractor than the main one the VM execute your program in, then it's technically still a global lock, but you now have (limited) ways to go around it.
Edit: as the sibling comment mentions, that’s part of what Ractor is trying to solve.