Senior Track Roadmap

Ruby: GVL deep dive

This course examines the Global VM Lock (GVL) in CRuby, the lock that guards the virtual machine's own state. It covers what the lock protects inside the VM and why your shared data sits outside that list. Lessons show a counter losing increments without a Mutex, explain when the lock is released around I/O, sleep and C extensions, and describe timer preemption and the M:N scheduler. The course closes with measuring wall time against CPU time and applying the results to Puma threads and Ractors in a Rails process.

What you'll learn

  • ✓What the GVL protects inside the VM and what it leaves unprotected
  • ✓Why a shared counter needs a Mutex even with the GVL
  • ✓When the lock is released around blocking I/O, sleep and C extensions
  • ✓How timer preemption and the M:N scheduler affect Ruby threads
  • ✓How to compare wall time with CPU time to find GVL-bound work
  • ✓How to set Puma's thread count and weigh Ractors in a Rails process
Free preview · Lesson 1 4 min read

The lock and its name

Two engineers are looking at the same graph. Puma runs sixteen threads, the box has eight cores, and CPU sits at 12% while p95 latency climbs. One says "the GIL is the problem". The other says "we aren't even CPU-bound, add threads". Both are arguing about a lock neither of them has ever measured.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...