Heroku R14在重启时立即出错

时间:2014-07-03 20:58:15

标签: ruby-on-rails heroku memory-leaks

我有一个heroku应用程序,它有一个我无法找到的内存泄漏。一旦我重新启动应用程序,它会立即达到100%+ RAM并吐出R14 errors。我尝试使用oink进行调试,但没有看到任何消耗大量RAM的特定进程。我还查看了New Relic监控没有结果。它是全面的,进程很慢,这是因为应用程序在磁盘内存上运行,因为RAM已经填满。

我也尝试增加Heroku的dynos数量,但我没有得到任何更好的表现因为每个dyno也立即填满。

我正在使用mongoid,但我认为这不是数据库问题,因为我没有在应用程序加载时实例化任何对象(但是无法让oink工作与mongoid,所以不确定这一点。)

如果它的级别太低,我如何调试问题?如果我需要包含与调试相关的任何其他内容,请告诉我们。

Procfile:

web: bundle exec puma -w 3 -t 16:16 -p $PORT -e $RACK_ENV

New Relic Memory用法: Memory Usage in New Relic

的Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '~> 3.2.12'

gem 'andand'
gem 'rack-reverse-proxy', :require => 'rack/reverse_proxy'
gem 'retina_rails'
gem 'mixpanel-ruby'
gem 'newrelic_rpm'
gem 'browser'
gem 'iconv' # FIXME: What's using iconv but not depending on it?
gem 'mongoid', '~> 3.1.2'
gem 'sitemap_generator'
gem 'bson_ext'
gem 'mongoid_token', :git => 'git://github.com/thetron/mongoid_token.git', :branch => 'patch/collisions-define-method'
gem 'mongoid-app_settings'
gem 'state_machine'
gem 'devise'
gem 'cocoon'
gem 'faraday'
gem 'faraday_middleware'
gem 'multi_xml'
gem 'nullobject'
gem 'rails_admin'
gem 'high_voltage'
gem 'page_title_helper'
gem 'sidekiq', '~> 2.2.1'
gem 'autoscaler'
gem 'holidays'
gem 'masked_input-rails'
gem "steps-rails"

gem 'remote_table', github: 'seamusabshere/remote_table'
gem 'hello_sign', github: "jgarber/hello_sign"
gem 's3_direct_upload'
gem 'fog'
gem 'prawn', "= 0.12.0" # monkeypatched in initializer

group :production, :staging do
  gem "sentry-raven", :git => "https://github.com/getsentry/raven-ruby.git" # exception handling
  gem 'heroku-deflater'
  gem 'bounscale'
  gem "heroku-mongo-backup"
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

group :development, :test do
  gem 'holder_rails'
  gem 'dotenv-rails'
  gem 'quiet_assets'
  gem 'shoulda-matchers'
  gem 'pry-debugger'
  gem 'pry-remote'
  gem 'rb-fsevent'
  gem "rspec-rails"
  gem 'guard-rspec'
  gem 'vcr'
  gem 'thin'
end

group :test do
  gem 'email_spec'
  gem 'database_cleaner'
  gem 'factory_girl_rails'
  gem 'cucumber-rails', require: false
  gem 'poltergeist'
  gem 'selenium-webdriver', '~> 2.42.0'
  gem 'rubyzip', '~> 1.1'
end

group :development, :staging do
  gem 'letter_opener_web'
  gem "oink"
end

gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'
gem 'chosen-rails'
gem 'chosen-sass-bootstrap-rails', github: 'duncanparkinson/chosen-sass-bootstrap-rails' # dependency versions less stringent
#gem 'slim-rails' # wasn't working with slim 2.0.0.
gem 'slim', '>= 2.0.0'
gem 'jquery-rails'
gem 'loadjs'
gem 'simple_form', '~> 2.1.0'
gem 'wicked'
gem 'area'
gem 'american_date'
gem 'stripe'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
#gem 'unicorn'
gem 'puma'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

group :development do
  gem 'foreman'
  gem 'capybara-console'
end

# Docusign
gem "docusign_rest", github: "Hunter-Dolan/docusign_rest", branch: "template-custom-fields"

日志文件:

2014-07-03T20:47:11.751231+00:00 app[web.1]: [2] - Gracefully shutting down workers...
2014-07-03T20:47:10.985359+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-07-03T20:47:15.816388+00:00 app[web.1]: [2] - Goodbye!
2014-07-03T20:47:16.879719+00:00 app[web.1]: [2] Puma starting in cluster mode...
2014-07-03T20:47:16.879756+00:00 app[web.1]: [2] * Version 2.6.0, codename: Pantsuit Party
2014-07-03T20:47:16.879758+00:00 app[web.1]: [2] * Min threads: 16, max threads: 16
2014-07-03T20:47:16.879760+00:00 app[web.1]: [2] * Environment: staging
2014-07-03T20:47:16.879761+00:00 app[web.1]: [2] * Process workers: 3
2014-07-03T20:47:16.879763+00:00 app[web.1]: [2] * Phased restart available
2014-07-03T20:47:16.880229+00:00 app[web.1]: [2] * Listening on tcp://0.0.0.0:4697
2014-07-03T20:47:16.880530+00:00 app[web.1]: [2] Use Ctrl-C to stop
2014-07-03T20:47:17.334021+00:00 heroku[web.1]: State changed from starting to up
2014-07-03T20:47:15.032318+00:00 heroku[web.1]: Starting process with command `bundle exec puma -w 3 -t 16:16 -p 4697 -e staging`
2014-07-03T20:47:17.263991+00:00 heroku[web.1]: Process exited with status 0
2014-07-03T20:47:23.635887+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:23.821768+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:23.636332+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:23.822488+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:24.650971+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:24.651395+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2014-07-03T20:47:25.446267+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Starting the New Relic agent in "staging" environment.
2014-07-03T20:47:25.446364+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : To prevent agent startup add a NEWRELIC_ENABLE=false environment variable or modify the "staging" section of your newrelic.yml.
2014-07-03T20:47:25.446423+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Reading configuration from config/newrelic.yml
2014-07-03T20:47:25.449056+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Enabling the Request Sampler.
2014-07-03T20:47:25.449488+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Environment: staging
2014-07-03T20:47:25.449563+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Dispatcher: puma
2014-07-03T20:47:25.449676+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Application: staging
2014-07-03T20:47:25.700934+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Net instrumentation
2014-07-03T20:47:25.708768+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Mongo instrumentation
2014-07-03T20:47:25.717379+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing deferred Rack instrumentation
2014-07-03T20:47:25.717785+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Rails 3.1/3.2 view instrumentation
2014-07-03T20:47:25.717913+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Rails3 Error instrumentation
2014-07-03T20:47:25.717993+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Finished instrumentation
2014-07-03T20:47:25.778682+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Starting the New Relic agent in "staging" environment.
2014-07-03T20:47:25.778783+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : To prevent agent startup add a NEWRELIC_ENABLE=false environment variable or modify the "staging" section of your newrelic.yml.
2014-07-03T20:47:25.778837+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Reading configuration from config/newrelic.yml
2014-07-03T20:47:25.783896+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Enabling the Request Sampler.
2014-07-03T20:47:25.706445+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing middleware-based Excon instrumentation
2014-07-03T20:47:25.715460+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Sidekiq instrumentation
2014-07-03T20:47:25.717602+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Installing Rails 3 Controller instrumentation
2014-07-03T20:47:25.784780+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Environment: staging
2014-07-03T20:47:25.784874+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Dispatcher: puma
2014-07-03T20:47:25.784990+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:25 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Application: staging
2014-07-03T20:47:26.038988+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Net instrumentation
2014-07-03T20:47:26.049103+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Mongo instrumentation
2014-07-03T20:47:26.059261+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing deferred Rack instrumentation
2014-07-03T20:47:26.059684+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Rails 3.1/3.2 view instrumentation
2014-07-03T20:47:26.059879+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Rails3 Error instrumentation
2014-07-03T20:47:26.060018+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Finished instrumentation
2014-07-03T20:47:26.045499+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing middleware-based Excon instrumentation
2014-07-03T20:47:26.059020+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Sidekiq instrumentation
2014-07-03T20:47:26.059466+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Installing Rails 3 Controller instrumentation
2014-07-03T20:47:26.368273+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Reporting to: https://rpm.newrelic.com/accounts/677464/applications/3061766
2014-07-03T20:47:26.458487+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Environment: staging
2014-07-03T20:47:26.458578+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Dispatcher: puma
2014-07-03T20:47:26.458581+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Application: staging
2014-07-03T20:47:26.548922+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Reporting to: https://rpm.newrelic.com/accounts/677464/applications/3061766
2014-07-03T20:47:26.455500+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Starting the New Relic agent in "staging" environment.
2014-07-03T20:47:26.455631+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : To prevent agent startup add a NEWRELIC_ENABLE=false environment variable or modify the "staging" section of your newrelic.yml.
2014-07-03T20:47:26.455717+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Reading configuration from config/newrelic.yml
2014-07-03T20:47:26.458187+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Enabling the Request Sampler.
2014-07-03T20:47:26.668916+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Net instrumentation
2014-07-03T20:47:26.688577+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Mongo instrumentation
2014-07-03T20:47:26.681101+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing middleware-based Excon instrumentation
2014-07-03T20:47:26.705940+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Sidekiq instrumentation
2014-07-03T20:47:26.708413+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing deferred Rack instrumentation
2014-07-03T20:47:26.708421+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Rails 3 Controller instrumentation
2014-07-03T20:47:26.708423+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Rails 3.1/3.2 view instrumentation
2014-07-03T20:47:26.708424+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Installing Rails3 Error instrumentation
2014-07-03T20:47:26.708426+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:26 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Finished instrumentation
2014-07-03T20:47:27.370289+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:27 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Reporting to: https://rpm.newrelic.com/accounts/677464/applications/3061766
2014-07-03T20:47:27.582068+00:00 app[web.1]: ** [Raven] Raven 0.4.8 ready to catch errors
2014-07-03T20:47:28.393745+00:00 app[web.1]: ** [Raven] Raven 0.4.8 ready to catch errors
2014-07-03T20:47:29.305090+00:00 app[web.1]: ** [Raven] Raven 0.4.8 ready to catch errors
2014-07-03T20:47:30.534618+00:00 heroku[web.1]: source=web.1 dyno=heroku.12874609.85ab02a7-2014-4901-9350-f39a9724e11b sample#memory_total=513.47MB sample#memory_rss=511.88MB sample#memory_cache=0.00MB sample#memory_swap=1.59MB sample#memory_pgpgin=136551pages sample#memory_pgpgout=5511pages
2014-07-03T20:47:30.535205+00:00 heroku[web.1]: Process running mem=513M(100.3%)
2014-07-03T20:47:30.535457+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2014-07-03T20:47:32.487456+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:32 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (9)] INFO : Doing deferred dependency-detection before Rack startup
2014-07-03T20:47:32.845196+00:00 app[web.1]: [2] - Worker 9 booted, phase: 0
2014-07-03T20:47:33.253529+00:00 app[web.1]: Started HEAD "/" for 54.247.188.179 at 2014-07-03 16:47:33 -0400
2014-07-03T20:47:33.482376+00:00 app[web.1]: [2] - Worker 5 booted, phase: 0
2014-07-03T20:47:33.481842+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:33 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (5)] INFO : Doing deferred dependency-detection before Rack startup
2014-07-03T20:47:34.059295+00:00 heroku[router]: at=info method=HEAD path="/" host=myapp.herokuapp.com request_id=64d068d2-a4dc-44d4-874d-d0a2fc233157 fwd="54.247.188.179" dyno=web.1 connect=4ms service=14817ms status=200 bytes=1150
2014-07-03T20:47:33.870224+00:00 app[web.1]: Jul 03 16:47:33 85ab02a7-2014-4901-9350-f39a9724e11b rails[9]: Oink Action: home#index
2014-07-03T20:47:33.969379+00:00 app[web.1]: Jul 03 16:47:33 85ab02a7-2014-4901-9350-f39a9724e11b rails[9]: Memory usage: 406532 | PID: 9
2014-07-03T20:47:33.969419+00:00 app[web.1]: Jul 03 16:47:33 85ab02a7-2014-4901-9350-f39a9724e11b rails[9]: Oink Log Entry Complete
2014-07-03T20:47:34.055371+00:00 app[web.1]: b74e646e-7e55-448f-814d-e36eedc44ea9{"format_ver":0,"datetime":"2014-07-03 16:47:34 -0400","data":[{"name":"cpu","value":419.99999999999835},{"name":"memory","value":184.875},{"name":"busyness","value":0},{"name":"throughput","value":0}],"framework_ver":"Rails 3.2.14"}4a061908-db52-4224-ad4b-9850a47c7edf
2014-07-03T20:47:36.243895+00:00 heroku[router]: at=info method=HEAD path="/" host=myapp.herokuapp.com request_id=02655c94-7288-482e-bd20-ca77837e64b4 fwd="54.247.188.179" dyno=web.1 connect=0ms service=5ms status=301 bytes=167
2014-07-03T20:47:41.730828+00:00 heroku[router]: at=info method=HEAD path="/" host=myapp.herokuapp.com request_id=f7f58e72-ee99-445c-97a0-2ede3eabfe0d fwd="50.31.164.139" dyno=web.1 connect=0ms service=249ms status=301 bytes=167
2014-07-03T20:47:41.965324+00:00 app[web.1]: ** [NewRelic][07/03/14 16:47:41 -0400 85ab02a7-2014-4901-9350-f39a9724e11b (13)] INFO : Doing deferred dependency-detection before Rack startup
2014-07-03T20:47:41.966048+00:00 app[web.1]: [2] - Worker 13 booted, phase: 0
2014-07-03T20:47:46.318773+00:00 heroku[router]: at=info method=HEAD path="/" host=myapp.herokuapp.com request_id=ab9072f3-145e-4f3d-b524-7ff98a64ee4c fwd="54.251.34.67" dyno=web.1 connect=1ms service=23ms status=301 bytes=167
2014-07-03T20:47:49.403750+00:00 app[web.1]: Started HEAD "/" for 50.112.95.211 at 2014-07-03 16:47:49 -0400
2014-07-03T20:47:49.987482+00:00 heroku[router]: at=info method=HEAD path="/" host=myapp.herokuapp.com request_id=97e23913-fa7f-48a6-90a3-861bdf07be9d fwd="50.112.95.211" dyno=web.1 connect=0ms service=601ms status=200 bytes=1149
2014-07-03T20:47:49.825456+00:00 app[web.1]: Jul 03 16:47:49 85ab02a7-2014-4901-9350-f39a9724e11b rails[13]: Oink Action: home#index
2014-07-03T20:47:49.910239+00:00 app[web.1]: Jul 03 16:47:49 85ab02a7-2014-4901-9350-f39a9724e11b rails[13]: Memory usage: 472088 | PID: 13
2014-07-03T20:47:49.910300+00:00 app[web.1]: Jul 03 16:47:49 85ab02a7-2014-4901-9350-f39a9724e11b rails[13]: Oink Log Entry Complete
2014-07-03T20:47:49.983950+00:00 app[web.1]: b74e646e-7e55-448f-814d-e36eedc44ea9{"format_ver":0,"datetime":"2014-07-03 16:47:49 -0400","data":[{"name":"cpu","value":379.999999999999},{"name":"memory","value":179.828125},{"name":"busyness","value":0},{"name":"throughput","value":0}],"framework_ver":"Rails 3.2.14"}4a061908-db52-4224-ad4b-9850a47c7edf
2014-07-03T20:47:50.238718+00:00 heroku[web.1]: source=web.1 dyno=heroku.12874609.85ab02a7-2014-4901-9350-f39a9724e11b sample#memory_total=552.01MB sample#memory_rss=511.59MB sample#memory_cache=0.00MB sample#memory_swap=40.42MB sample#memory_pgpgin=155493pages sample#memory_pgpgout=24526pages
2014-07-03T20:47:50.239253+00:00 heroku[web.1]: Process running mem=552M(107.8%)
2014-07-03T20:47:50.239467+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)

---更新:对象实例数#----

运行下面的代码可以看到strings和其他各种对象的实例。我认为strings的数量太高,但我无法找到有关如何深入了解创建字符串的信息。

ObjectSpace.each_object.with_object(Hash.new(0)){ |obj, h|
  h[obj.class] += 1
}.select{
|k,v| puts "#{k} => #{v}" if k == String || k == Array || k == Hash}

String => 689832
Array => 78652
Hash => 3390

1 个答案:

答案 0 :(得分:0)

经过大量的调试和尝试不同的事情,我最终发现问题出在服务器配置上。我的Procfile曾经读过:

web: bundle exec puma -w 3 -t 16:16 -p $PORT -e $RACK_ENV

最大化线程为16,有3名工人。我在阅读this article后对其进行了更新。我打算做更多的调试,看看哪些表现最好,但这已经是性能的巨大提升。

web: bundle exec puma -t ${PUMA_MIN_THREADS:-8}:${PUMA_MAX_THREADS:-12} -w ${PUMA_WORKERS:-2} -p $PORT -e ${RACK_ENV:-development}