Mid-level Track Roadmap

Scaling: horizontal Puma

This course covers how to size and run a Rails application on Puma, first on one machine and then across several. It explains workers and threads, the GVL, and how cores, memory and database connections limit the worker count. It covers connection pools and PgBouncer, preload_app! and copy-on-write, memory leaks versus fragmentation, and the kinds of Puma restarts. It then looks at statelessness, load balancer routing and health checks, and ends with a full configuration for a 4-core, 8GB host.

What you'll learn

  • ✓How Puma workers and threads differ, and how the GVL affects each
  • ✓Choosing worker and thread counts from cores, memory, connections and request queue time
  • ✓Calculating database connections across hosts, workers and pools
  • ✓How preload_app!, copy-on-write and allocator settings affect memory
  • ✓Hot restarts, phased restarts, SIGTERM draining and worker_timeout
  • ✓What an application needs to run on more than one machine
Free preview · Lesson 1 4 min read

The two dials: workers and threads

Open config/puma.rb in this repository. Its comments already explain the model, and the file is short enough to read in full:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...