evilmartians / ruby-on-whales

Ruby on Whales example and templates
MIT License
295 stars 26 forks source link

fix: Disable clustered mode for Puma #7

Closed oliverklee closed 2 years ago

oliverklee commented 2 years ago

Puma is not intended to be used in clustered mode for local development and emits a warning on start if it is configured to use one worker in clustered mode (instead of 0 workers, which disables clustered mode).

palkan commented 2 years ago

Puma is not intended to be used in clustered mode for local development

Why so? One particular reason I prefer to use Puma in a clustered mode locally to catch fork-related problems as early as possible.

oliverklee commented 2 years ago

My main motivation is to avoid warnings. (I'd like to have my application run warning-free so we can use warnings as a sign that something is broken, which does not work if we get used to ignoring warnings. This is why this is quite important to me.)

This is the warning I get if I start our application using dip rails s:

klee@gonzales ~/src/ruby/justworkshops (task/ruby-on-whales)$ dip rails s
Creating justworkshops_webpacker_1 ... done
Creating justworkshops_sidekiq_1   ... done
Creating justworkshops_web_run     ... done
=> Booting Puma
=> Rails 6.1.5 application starting in development 
=> Run `bin/rails server --help` for more startup options
[1] Puma starting in cluster mode...
[1] * Puma version: 5.6.2 (ruby 3.1.1-p18) ("Birdie's Version")
[1] *  Min threads: 5
[1] *  Max threads: 5
[1] *  Environment: development
[1] *   Master PID: 1
[1] *      Workers: 1
[1] *     Restarts: (✔) hot (✔) phased
[1] * Listening on http://0.0.0.0:3000
[1] Use Ctrl-C to stop
[1] ! WARNING: Detected running cluster mode with 1 worker.
[1] ! Running Puma in cluster mode with a single worker is often a misconfiguration.
[1] ! Consider running Puma in single-mode (workers = 0) in order to reduce memory overhead.
[1] ! Set the `silence_single_worker_warning` option to silence this warning message.
[1] - Worker 0 (PID: 14) booted in 0.01s, phase: 0

If I understand this correctly, having 0 as the default value does not stop the dev from providing a different value in the WEB_CONCURRENCY environment variable to use Puma in cluster mode, but it avoid the warning if no such environment variable is set.

palkan commented 2 years ago

If I understand this correctly, having 0 as the default value does not stop the dev from providing a different value in the WEB_CONCURRENCY environment variable to use Puma in cluster mode

Yeah, but my goal is to run in a cluster mode by default (so you can catch forking-related problems earlier).

but it avoid the warning if no such environment variable is set.

The warning could be disabled by the silence_single_worker_warning option (see example config).

oliverklee commented 2 years ago

The warning could be disabled by the silence_single_worker_warning option (see example config).

Ah, I didn't know there was an example config (and that this example here relies on the configuration). Would it make sense to include the example configuration in this repository?

palkan commented 2 years ago

Would it make sense to include the example configuration in this repository?

That could be added to the Readme (we need some kind of Troubleshooting section, I guess).