Last Updated: February 25, 2016
·
839
· estevaoam

How to run Ruby GC after a memory expensive request with Unicorn

Unicorn server has a module that you can import in your config.ru,
it's called Unicorn::OobGC, you can just import in your config.ru and call use:

require 'unicorn/oob_gc'

# GC ever two requests that hit /expensive/foo or /more_expensive/foo
# in your app.  By default, this will GC once every 5 requests
# for all endpoints in your app
use Unicorn::OobGC, 2, %r{\A/(?:expensive/foo|more_expensive/foo)}

It's in the official Unicorn documentation but most users don't pay attention.