Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Looks good, thanks @sengi

Co-authored-by: Chris B <chris.banks@digital.cabinet-office.gov.uk>
  • Loading branch information
Karl Baker and sengi authored Oct 26, 2021
1 parent c10d5cd commit 2985579
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions lib/govuk_app_config/govuk_puma.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,28 @@
module GovukPuma
def self.configure_rails(config)
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
config.port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
config.environment ENV.fetch("RAILS_ENV", "development")

if ENV["GOVUK_APP_LOGROOT"]
config.stdout_redirect "#{ENV['GOVUK_APP_LOGROOT']}/app.out.log" "#{ENV['GOVUK_APP_LOGROOT']}/app.err.log"
end

# Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments.
#
# `worker_timeout` specifies how many seconds Puma will wait before terminating a worker.
timeout = ENV.fetch("RAILS_ENV", "development") == "development" ? 3600 : 15
config.worker_timeout timeout

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# 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.
#
# When changing the mix/max threads for Puma, also consider changing ActiveRecord to match.
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count)
config.threads min_threads_count, max_threads_count

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# 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` specifies the number of worker processes that Puma will fork.
# The overall concurrency limit is worker count * max threads per worker.
config.workers ENV.fetch("WEB_CONCURRENCY", 2)

# 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!` tells Puma to load application code before forking worker processes.
# This reduces RAM wastage by making better use of copy-on-write.
config.preload_app!

config.before_fork do |_server|
Expand Down

0 comments on commit 2985579

Please sign in to comment.