Puma is a web server that helps your Rails app handle many users at the same time. Configuring Puma lets you control how your app runs smoothly and fast.
Puma server configuration in Ruby on Rails
# config/puma.rb threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads threads_count, threads_count port ENV.fetch("PORT") { 3000 } environment ENV.fetch("RAILS_ENV") { "development" } workers ENV.fetch("WEB_CONCURRENCY") { 2 } preload_app! on_worker_boot do ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) end
The threads line sets minimum and maximum threads Puma uses.
The workers line sets how many separate processes Puma runs for better performance.
threads 1, 5 port 3000 environment 'development'
workers 3
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection
endport ENV.fetch("PORT") { 8080 } environment ENV.fetch("RAILS_ENV") { "production" }
This is a complete Puma configuration file for a Rails app. It sets threads, port, environment, and workers using environment variables with defaults. It preloads the app and reconnects the database on worker boot.
# config/puma.rb threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads threads_count, threads_count port ENV.fetch("PORT") { 3000 } environment ENV.fetch("RAILS_ENV") { "development" } workers ENV.fetch("WEB_CONCURRENCY") { 2 } preload_app! on_worker_boot do ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) end
Use environment variables to easily change settings without editing the file.
Preloading the app helps workers start faster but needs proper database reconnect.
Adjust threads and workers based on your server's CPU and memory for best performance.
Puma configuration controls how your Rails app handles requests.
Set threads, workers, port, and environment to match your needs.
Use preload_app! and on_worker_boot for better worker management.