Last active
August 29, 2015 14:04
-
-
Save blaz/b1e7d6cda8cb393fb963 to your computer and use it in GitHub Desktop.
config.ru for heroku with oobgc and unicorn killer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### UNICORN KILLER | |
| if Integer(ENV['UNICORN_KILLER'] || 0) != 0 | |
| require 'unicorn/worker_killer' | |
| # Randomly kill worker between sizes 350M-400M, check every 30 requests, | |
| # and log memory checks | |
| min_mem = Integer(ENV['UNICORN_MEM_MIN'] || 350) | |
| max_mem = Integer(ENV['UNICORN_MEM_MAX'] || 400) | |
| puts "Unicorn killer enabled between #{min_mem}-#{max_mem}MB RSS usage" | |
| use Unicorn::WorkerKiller::Oom, (min_mem*(1024**2)), (max_mem*(1024**2)), 30, true | |
| end | |
| ### OOB GC | |
| if Integer(ENV['OOB_GC'] || 0) != 0 | |
| require 'unicorn/oob_gc' | |
| gc_frequency = Integer(ENV['GC_FREQUENCY'] || 20) | |
| puts "Unicorn OobGC enabled and running every #{gc_frequency} requests" | |
| # Don't run GC during requests | |
| GC.disable | |
| # Run Oob GC every N requests | |
| use Unicorn::OobGC, gc_frequency | |
| end | |
| ### LOAD Rails | |
| require ::File.expand_path('../config/environment', __FILE__) | |
| run Rails.application | |
| ### CORS | |
| require 'rack/cors' | |
| use Rack::Cors do | |
| allow do | |
| origins '*' | |
| resource '/api/v1/*', headers: :any, methods: [:get, :put, :post, :options, :create, :delete] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment