zombocom / puma_worker_killer

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

Unable to get it working with 3.12 / Rails 5.2 #61

Closed oyeanuj closed 4 years ago

oyeanuj commented 6 years ago

Hi @schneems,

I've spent some time debugging and I'm sure that there is something obvious that I've missed but am unable to figure it out:

I don't see the PumaWorkerKiller message on booting the app. Here's what I see:

2018-07-27T05:16:45.673728+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-07-27T05:16:45.673787+00:00 app[web.1]: [4] * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
2018-07-27T05:16:45.673790+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-07-27T05:16:45.673792+00:00 app[web.1]: [4] * Environment: production
2018-07-27T05:16:45.673794+00:00 app[web.1]: [4] * Process workers: 2
2018-07-27T05:16:45.673795+00:00 app[web.1]: [4] * Preloading application
2018-07-27T05:16:50.800023+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:10965
2018-07-27T05:16:50.800204+00:00 app[web.1]: [4] ! WARNING: Detected 1 Thread(s) started in app boot:
2018-07-27T05:16:50.800265+00:00 app[web.1]: [4] ! #<Thread:0x0000000004d34b00@/app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:297 sleep> - /app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:299:in `sleep'
2018-07-27T05:16:50.800355+00:00 app[web.1]: [4] Use Ctrl-C to stop
2018-07-27T05:16:50.839300+00:00 app[web.1]: [4] - Worker 0 (pid: 9) booted, phase: 0
2018-07-27T05:16:50.842525+00:00 app[web.1]: [4] - Worker 1 (pid: 13) booted, phase: 0
2018-07-27T05:16:51.024199+00:00 heroku[web.1]: State changed from starting to up

Here is what the relevant section of my puma.rb section looks like:

preload_app!

# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
before_fork do
  ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)

  # Restart Puma workers on a rolling basis
  require 'puma_worker_killer'
  PumaWorkerKiller.enable_rolling_restart # Default is every 6 hours
end

Any thoughts on what might be missing?

Thank you!

oyeanuj commented 6 years ago

@schneems Just checking in to see if you had any ideas on what might be the best way to debug this and figure out why its not working?

schneems commented 6 years ago

I suggest pulling it out into a separate https://www.codetriage.com/example_app to see if it works when trying to reproduce the issue.

kceb commented 5 years ago

I have the same version of Puma, and I noticed that puma_memory.rb calls ObjectSpace.each_object(Puma::Cluster).map { |obj| obj }.first if defined?(Puma::Cluster).

When I call Puma::Cluster manually in the rails console, it is undefined.

schneems commented 4 years ago

I suggest pulling it out into a separate https://www.codetriage.com/example_app to see if it works when trying to reproduce the issue.