Introduction to Concurrency in Ruby
summary
Builds a tiny Slack‑like chat server and implements it three ways so differences are concrete: multi‑process with fork and pipes (Unicorn style), multi‑thread with a shared messages array and a mutex (watch for deadlocks and the GIL), and evented using Fiber and IO.select (EventMachine‑style tradeoffs). Shows why Puma/Unicorn/ActionCable make different choices, measures memory and threading behavior on a laptop, and demos each version — the evented and threaded ones run; the multi‑process approach is the most fragile.
AI-written summary · about
chapters (17)
- 0:00Start
- 2:40Our chat client
- 5:33Communicate between processes
- 6:46Start a worker process
- 8:34What's running in the worker process
- 11:59Start a TCP server (exactly the same)
- 12:11Store incoming messages
- 13:46Run a thread per connection
- 14:47Store a message
- 15:21Send messages to the client
- 20:49The mental model...
- 23:50Fibers
- 25:42The client representation
- 27:04Structure of the event loop
- 27:42Accept incoming connections
- 28:36Read from readable connections
- 28:49Write to writable connections
related talks
54mConcurrency: Rubies, plural
39mConcurrent Systems in Ruby
30mAdvanced Multithreading in Ruby
27mIn-Depth Ruby Concurrency: Navigating the Ruby concurrency landscape
37mLetting Concurrency Help You Today
20mSubprocesses, Threads and Fibers
36mModern Concurrency Practices in Ruby
26mConcurrency in Ruby: From fork() to Fiber
