zombocom / puma_worker_killer

Automatically restart Puma cluster workers based on max RAM available
748 stars 77 forks source link

Can I run both enable_rolling_restart and start #53

Closed nitzanav closed 4 years ago

nitzanav commented 6 years ago

Hi,

Can I run both enable_rolling_restart and start?

Is this safe?

before_fork do
  require 'puma_worker_killer'
  PumaWorkerKiller.config do |config|
    config.ram           = 512 # mb
    config.percent_usage = 0.98
  end
  PumaWorkerKiller.enable_rolling_restart # Default is every 6 hours
  PumaWorkerKiller.start
end
schneems commented 6 years ago

I’m not sure. I think it should be ok. You running into problems?

DemonGiggle commented 6 years ago

I don't think it's a good idea.

In this case, you will have 3 threads to do reaping. Two are for rolling restart.

The two for rolling restart will perform its work within few seconds, which mean there exists a case as the following sequence shows (assume you have two puma workers here):

  1. rolling_restart_1 close the worker_1 and wait 1 minute (default)
  2. puma remove a dead worker (worker_1) from @workers
  3. rolling_restart_2 check the @workers list and currently, only one remains, but it still remove it, said worker_2
  4. puma continues its work, so it create a worker and inserted to @workers

The problem is that there will be a short downtime before step 4 (if the worker takes longer to initialize, the downtime will increase)

Actually, it may still happen even if two reaper exists (one is for oom checker, and the other is for rolling restart)