No commit activity in last 3 years
No release in over 3 years
Kill Unicorn child processes when they exceed memory/request limits
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

unicorn-worker-killer 2

This is a reimplementation of https://github.com/kzk/unicorn-worker-killer.

It's a lot faster because it doesn't pretend to be a middleware, and doesn't iterate over ObjectSpace for every request. Instead, you set it up in Unicorn's after_fork handler, like so;

after_fork do |_server, _worker|
  # Restart a Unicorn process when it uses more than 192MB.
  Unicorn::WorkerKiller::Oom.monkey_patch(
    memory_limit_min: 192 * (1024**2),
    memory_limit_max: 256 * (1024**2),
    check_cycle: 128, verbose: true
  )

  # Restart Unicorn workers after about 5000 requests:
  Unicorn::WorkerKiller::MaxRequests.monkey_patch(
    max_requests_min: 5000,
    max_requests_max: 6000,
    verbose: true
  )
end

This is measurably faster; I tested an app before adding any killer at about 7100 requests/second. Adding the original killer slows it down to around 1100 requests/second. This one barely has any impact and the app still manages around 7000 requests/second.

It's horrible and hacky and monkeypatches Unicorn, but then again so did the original one.

It has no tests but neither did the original one.