Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Last active March 19, 2023 18:13
Show Gist options
  • Save henrypoydar/55a50da016d8430976d182fb525e94b0 to your computer and use it in GitHub Desktop.
Save henrypoydar/55a50da016d8430976d182fb525e94b0 to your computer and use it in GitHub Desktop.
Rails + Sidekiq + Puma + Heroku
production:
adapter: postgresql
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
WEB_PROCESSES=2
WEB_THREADS=5
WORKER_THREADS=15
web: RAILS_MAX_THREADS=$WEB_THREADS bundle exec puma -C config/puma.rb
worker: RAILS_MAX_THREADS=$WORKER_THREADS bundle exec sidekiq -C config/sidekiq.yml
threads_count = ENV.fetch("WEB_THREADS") { 5 }.to_i
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
workers ENV.fetch("WEB_PROCESSES") { 3 }.to_i
preload_app!
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
Rails.logger.info("Database connection pool size for this web process is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end
---
:concurrency: <%= ENV['WORKER_THREADS'] %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment