2

For some time I've been having a memory leak in my application. The current setup runs with Ruby 2.3.0, Rails 4.2 and Puma Webserver puma 2.15.3 It is recommended by Heroku to use Puma, however a lot of debugging has lead me to believe it's actual Puma Webserver which is the cause of all the troubles. During debugging I've removed most of the gems, code etc but the issue kept showing up, RAM Memory increasing until an out of memory showed up. This is why I'm 99,999% sure the leak isn't from my application. Next I installed "Thin" Webserver on my Development system and also this was not a solution. Then I also upgraded my ruby version to 2.3.0 and the leak was immediately solved, RAM usage stayed ok.

Due to this evolution, I upgraded my production system to Ruby 2.3.0 (thinking it was only a ruby version issue) but still I'm having the memory leak. I'm now at the point that it seems to be a combination of my Puma Webserver, together with Ruby 2.3.0...

Does anyone of you have any experience with Puma giving memory leaks with Ruby 2.3.0.

Thanks in advance, T

UPDATE: my puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end
Thomas C
  • 714
  • 1
  • 6
  • 15
  • There aren't any issues on puma's github about memory leaks. I'd suggest posting there. – j-dexx Jun 13 '16 at 09:40
  • Good tip, I added the issue there too. Thanks! – Thomas C Jun 13 '16 at 09:47
  • I recently ran into a very similar issue and it ended up being some assets I loaded that only caused a memory leak on the production environment and not my local. If you are loading any libraries on the page where your memory spikes I would try commenting them out and see if it still occurrs. – bkunzi01 Jun 13 '16 at 13:02
  • I don't have any answer only a debug suggestion, have you used NewRelic? Even the free version gives you visibility into heap and how much memory is being chomped by modules. It also offers a garbage collection feature. https://newrelic.com/ – Elvn Jun 13 '16 at 15:48

0 Answers0