diff --git a/config/puma.rb b/config/puma.rb index 65ff8b776..68fefbb71 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,16 +1,3 @@ -# Puma starts a configurable number of processes (workers) and each process -# serves each request in a thread from an internal thread pool. -# -# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You -# should only set this value when you want to run 2 or more workers. The -# default is already 1. -# -# Any libraries that use a connection pool or another resource pool should -# be configured to provide at least as many connections as the number of -# threads. This includes Active Record's `pool` parameter in `database.yml`. -threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) -threads threads_count, threads_count - # Specifies the `port` that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT", 3000) @@ -29,3 +16,11 @@ control_uri = Rails.env.local? ? "unix://tmp/pumactl.sock" : "auto" activate_control_app control_uri, no_token: true plugin :yabeda plugin :yabeda_prometheus + +# Because we expect fewer I/O waits than Rails apps that connect to the +# database over the network, let's start with a baseline config of 1 +# worker per CPU, 1 thread per worker and tune it from there. +# +# https://edgeguides.rubyonrails.org/tuning_performance_for_deployment.html#puma +workers Concurrent.physical_processor_count +threads 1, 1