Skip to content

Instantly share code, notes, and snippets.

@onedal
Created August 11, 2016 07:59
Show Gist options
  • Save onedal/fbf1403320ce4c38a1a41bdd928ae875 to your computer and use it in GitHub Desktop.
Save onedal/fbf1403320ce4c38a1a41bdd928ae875 to your computer and use it in GitHub Desktop.
puma config with worker killer
require 'puma_worker_killer'
#require 'fileutils'
rails_env = ENV['RAILS_ENV'] || 'development'
app_dir = Dir.pwd
environment rails_env
case rails_env
when 'development'
port ENV['PORT'] || 9292
# Set master PID and state locations
pidfile "#{app_dir}/tmp/pids/puma.pid"
stdout_redirect "#{app_dir}/log/stdout", "#{app_dir}/log/stderr", true
bind "unix:///#{app_dir}/tmp/sockets/puma.sock"
before_fork do
PumaWorkerKiller.config do |config|
config.ram = 2048 # mb
config.frequency = 60 # seconds
config.percent_usage = 0.98
config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds
end
PumaWorkerKiller.start
end
#daemonize true
workers 1
threads 1, 16
on_worker_boot do
require 'active_record'
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
when 'production'
# Set master PID and state locations
pidfile "#{app_dir}/shared/pids/puma.pid"
stdout_redirect "#{app_dir}/log/stdout", "#{app_dir}/log/stderr", true
bind "unix:///#{app_dir}/shared/sockets/puma.sock"
before_fork do
PumaWorkerKiller.config do |config|
config.ram = 16384 # mb
config.frequency = 10 # seconds
config.percent_usage = 0.98
config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds
end
PumaWorkerKiller.start
end
#daemonize true
workers 4
threads 16, 64
preload_app!
on_worker_boot do
require 'active_record'
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment