zombocom/puma_worker_killer

Seems to be not working when Puma is detached from the console

mmonsta opened this issue · 5 comments

When Puma is detached from the console (daemonize true) the gem stops sending messages to the Puma log and no longer kills oversized workers. Using Puma 2.8.2, Rails 4.0.3, PWK 0.0.3.

You have to run PumaWorkerKiller.start in a process that does not get killed. Not sure how to get around this. I'll need to investigate some here.

The after_worker_boot hook in puma.rb seems to be a good candidate for launching puma_worker_killer, it runs under the already detached master pid and it survives restarts, it just needs to be limited to not call PumaWorkerKiller.start more than once.

My quick hack:

pwk_started = false
after_worker_boot do
  unless pwk_started
    pwk_started = true
    PumaWorkerKiller.config do |config|
      config.ram           = 512 # mb
      config.frequency     = 10    # seconds
      config.percent_usage = 0.5
    end
    PumaWorkerKiller.start
  end
end

Would be nice to have this in the readme.

Maybe we should make start look for a mutex and only start once per process and check to see if the thread is still alive so we can get around the unless pwk_started code.

If there's a bug here can you give me a reproduction and open a new issue please?