Rails server & Puma
This course covers how a Rails app is started and served by Puma. It begins with bin/rails server and its boot output, then explains why Puma replaced WEBrick as the Rails default. It reads config/puma.rb line by line, including threads, port and plugins. It describes Puma's workers and threads, single and clustered mode, and the database connection pool. It also covers bin/dev with Foreman, the ways to restart the server, and how to clear a stale pidfile error.
What you'll learn
- ✓Starting and stopping the Rails server with bin/rails server
- ✓Why Puma replaced WEBrick as the Rails default server
- ✓Reading the settings in config/puma.rb
- ✓Puma workers, threads, and single versus clustered mode
- ✓Running several development processes with bin/dev and Foreman
- ✓Restarting Puma and clearing a stale pidfile
Starting the Rails server
Rails CLI: rails new generated a whole app: models, views, controllers and config, sitting on disk. None of it does anything yet. A Rails app is just files until a process starts reading requests and running the code. That process is bin/rails server.
Read the full lesson free →Curriculum
7 lessonsStarting the Rails server
Starting a Rails app with bin/rails server, reading Puma's boot output, and stopping it with Ctrl+C.
What is Puma, and why not WEBrick?
Why WEBrick left Ruby's default gems, where Puma came from, and why Rails made it the default.
Reading config/puma.rb
A line-by-line reading of config/puma.rb: threads, port, tmp_restart, Solid Queue, pidfile and ENV.fetch defaults.
Puma's concurrency model: workers and threads
How Puma uses worker processes and threads, single versus clustered mode, and why the connection pool must keep up.
bin/dev and Foreman
How bin/dev uses Foreman and Procfile.dev to run the Rails server and a Tailwind watcher together.
Stopping, restarting, and stale servers
Which changes need a restart, two ways to restart Puma, and how to clear a stale pidfile.
Putting it together: from rails new to a running app
Tracing bin/dev end to end to see how each piece of the course fits together.