Skip to content

Commit

Permalink
Puma config hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Jul 16, 2024
1 parent f2f1fff commit f833851
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# the maximum value specified for Puma. Default is set to 3 threads for minimum
# and maximum; this matches the default thread size of Rails 7.1.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 1) # FIXME: GB This is a hotfix for yet-unexplained performance issues
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

Expand Down Expand Up @@ -35,26 +35,14 @@
# Specifies that the worker count should equal the number of processors in production.
if ENV["RAILS_ENV"] == "production"
require "concurrent-ruby"
worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count })
worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.available_processor_count })
workers worker_count if worker_count > 1

# 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!

before_fork do
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
end

on_worker_boot do
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
end

# Allow puma to be restarted by `rails restart` command.
Expand Down

0 comments on commit f833851

Please sign in to comment.