From bfdec7fe64a05ff22367d40be56785648e8b53d1 Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:25:25 +0200 Subject: [PATCH] fix: Fine tuning Puma server --- config/puma.rb | 14 ++++++++------ docker-compose.local.yml | 10 ++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index a8adec5d..aa7672bc 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -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. # @@ -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 diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 4cd74d98..47847262 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -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: @@ -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: