Skip to content

Instantly share code, notes, and snippets.

@mockdeep
Created April 15, 2015 01:58

Revisions

  1. mockdeep created this gist Apr 15, 2015.
    18 changes: 18 additions & 0 deletions puma.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # 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
    8 changes: 8 additions & 0 deletions puma_worker_killer.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # 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