Home Possible memory leak on Heroku
Reply: 0

Possible memory leak on Heroku

user2742 Published in June 20, 2018, 10:46 pm

We have a Rails app running on heroku 2x dyno. In Paper-trail logs, the memory consumption of the app keeps on increasing linearly even without a request to the server, which reveals a possible memory leak.

The Gemfile.

source 'https://rubygems.org

ruby '2.1.2'

gem 'aasm', '~> 3.2.0'
gem 'american_date'
gem 'attr_encrypted'
gem 'sass-rails', '~> 4.0.3'
gem 'bootstrap-sass', '~>'
gem 'bugsnag'
gem 'carrierwave', '~> 0.10.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'devise', '~> 3.2.0'
gem 'fog', '~> 1.22.0'
gem 'foreigner', '~> 1.6.1'
gem 'hstore_accessor'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jquery-validation-rails', '~> 1.12.0'
gem 'omniauth-google-oauth2', '~> 0.2.0'
gem 'pg', '~> 0.17.0'
gem 'pundit', '~> 0.3.0'
gem 'rails', '4.1.4'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'simple_form', '~> 3.0.0'
gem 'spring',        group: :development
gem 'therubyracer',  platforms: :ruby
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'unicorn'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'feature'
gem 'finance'
gem 'cocoon'
gem 'accountingjs-rails'

group :development, :test do
  gem 'pry-byebug', '~> 1.3.0'
  gem 'pry-rails', '~> 0.3.0'

group :development do
  gem 'thin'
  gem 'rack-mini-profiler'
  gem 'rails_best_practices'
  gem 'rubocop'
  gem 'spring-commands-rspec'

group :test do
  gem 'capybara'
  gem 'codeclimate-test-reporter'
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'shoulda-matchers', require: false

group :production do
  gem 'skylight'

gem 'newrelic_rpm' #reccommended to load as late as possible

gem 'smarter_csv'

The new relic graphs shows the increase in memory usage.

We tried downgrading ruby version to 2.0 and the usage was incremental down but less gradual.

Is there any way to find whether the problem is with our code?. What are the possible methods to find the root cause?

**EDIT:* * (config/unicorn.rb)

worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 15
preload_app true

before_fork do |_server, _worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid

  defined?(ActiveRecord::Base) &&

after_fork do |_server, _worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'

  defined?(ActiveRecord::Base) &&
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313711 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO