Skip to content

Instantly share code, notes, and snippets.

@mockdeep
Created April 15, 2015 01:58
Show Gist options
  • Save mockdeep/4a9ec039bb7ee18825d0 to your computer and use it in GitHub Desktop.
Save mockdeep/4a9ec039bb7ee18825d0 to your computer and use it in GitHub Desktop.
Puma with worker killer
# config/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 1)
threads_count = Integer(ENV['MAX_THREADS'] || 2)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
config = ActiveRecord::Base.configurations[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['DB_POOL'] || 20
ActiveRecord::Base.establish_connection(config)
end
# config/initializers/puma_worker_killer.rb
PumaWorkerKiller.config do |config|
config.ram = (ENV.fetch('PUMA_WORKER_KILLER_RAM') { 512 }).to_i
config.frequency = (ENV.fetch('PUMA_WORKER_KILLER_FREQUENCY') { 10 }).to_i
config.percent_usage = (ENV.fetch('PUMA_WORKER_KILLER_PERCENT') { 0.99 }).to_f
end
PumaWorkerKiller.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment