Chase Gilliam Chase Gilliam - 1 year ago 135
Ruby Question

Run puma workers in Production, but not in Development

I'm running the following puma config

threads_count = Integer(ENV["DB_POOL"] || ENV["MAX_THREADS"] || 15)
threads threads_count, threads_count
workers 3

rackup DefaultRackup
port ENV["PORT"] || 3000
environment ENV["RACK_ENV"] || "development"

on_worker_boot do
ActiveSupport.on_load(:active_record) do

before_fork do

It's great for production, but I don't want to spin up 3 workers or use webrick in development. I tried wrapping the worker specific code in an environment check, but that breaks the puma DSL. Any ideas for running puma in non-clustered mode in development?

Answer Source

Rails is not defined in puma config file, so Rails.env can't be used here, but RACK_ENV is ok.

workers(ENV["RACK_ENV"] == "production" ? 3 : 0)