Skip to content

Instantly share code, notes, and snippets.

@localhots
Created August 27, 2014 13:14
Show Gist options
  • Save localhots/e168239f97ff757487a5 to your computer and use it in GitHub Desktop.
Save localhots/e168239f97ff757487a5 to your computer and use it in GitHub Desktop.
Unicorn worker killer + out-of-band garbage collection
require 'bundler'
Bundler.setup
require 'unicorn'
begin
# Unicorn self-process killer
require 'unicorn/worker_killer'
# Max requests per worker
use Unicorn::WorkerKiller::MaxRequests, 1000, 1500
# Max memory size (RSS) per worker
mb = 1024**2
use Unicorn::WorkerKiller::Oom, 400*mb, 500*mb
# Run garbage collection between requests
require 'unicorn/oob_gc'
GC.disable
use Unicorn::OobGC, 30 # each 30 requests
rescue LoadError
end
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment