Skip to content

Commit

Permalink
fix: Fine tuning Puma server
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Oct 25, 2023
1 parent 500a264 commit bfdec7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
threads threads_count, threads_count

min_threads_count = ENV.fetch("RAILS_MIN_THREADS", 5).to_i
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5).to_i
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
Expand All @@ -22,15 +23,16 @@
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
workers_count = ENV.fetch("WEB_CONCURRENCY", -1).to_i
workers workers_count if workers_count.positive?

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!

preload_app! if ENV.fetch("PUMA_PRELOAD_APP", "false") == "true"

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
10 changes: 10 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ services:
- SEED=true
- DEFACE_ENABLED=false
- QUESTION_CAPTCHA_HOST=
- ENABLE_RACK_ATTACK=0
- RAILS_MIN_THREADS=5
- RAILS_MAX_THREADS=5
- WEB_CONCURRENCY=4
- PUMA_PRELOAD_APP=true
depends_on:
- app
volumes:
Expand All @@ -60,6 +65,11 @@ services:
- SEED=true
- DEFACE_ENABLED=false
- QUESTION_CAPTCHA_HOST=
- ENABLE_RACK_ATTACK=0
- RAILS_MIN_THREADS=5
- RAILS_MAX_THREADS=5
- WEB_CONCURRENCY=4
- PUMA_PRELOAD_APP=true
volumes:
- shared-volume:/app
ports:
Expand Down

0 comments on commit bfdec7f

Please sign in to comment.