【问题标题】:Can someone advise me on Rails memory consumption?有人可以就 Rails 内存消耗给我建议吗?
【发布时间】:2011-08-05 20:02:13
【问题描述】:

我目前正在开发一个 Rails 应用程序,这似乎是致命的 我的 iMac 上的内存,直到我最终不得不重新启动。 我在 OSX 10.6 上有一个 2.66 GHZ 处理器和 4GB 内存。

当我启动 rails 应用程序时,内存消耗显示如下 (ps aux | grep rails):

Gavin      726   0.0  3.8  2590812 158860 s000  S+    9:27am 0:09.90  /Users/Gavin/.rvm/rubies/ree-1.8.7-2011.01/bin/ruby script/rails s 

RSS 为 158,860 kb 在对 localhost 进行几次请求后,这个数字会跳到:

Gavin      726   0.0 14.1  3031792 592888 s000  S+    9:27am 0:27.00  /Users/Gavin/.rvm/rubies/ree-1.8.7-2011.01/bin/ruby script/rails s 

592,888 KB!!

并且随着一般的开发使用,它会一次又一次地上升,并且 再次:

Gavin      726   1.5 25.0  3487516 1050180 s000  S+    9:27am 0:59.29 /Users/Gavin/.rvm/rubies/ree-1.8.7-2011.01/bin/ruby script/rails s 

我正在使用 RVM 运行 REE ruby 1.8.7(2010-12-23 补丁级别 330)[i686-darwin10.6.0],MBARI 0x6770, Ruby 企业版 2011.01

该应用正在使用 Rails 3.0.6

该应用程序不是特别密集的 SQL,几乎有 加载记录时不包含关联(在 建筑学)。

我说这是内存泄漏是对的还是有其他问题 我应该看看?

有人可以就我如何解决这个问题提供一些建议吗?

谢谢!

这里是使用的宝石的完整列表,以防万一有任何已知 里面的嫌疑人:

source 'http://rubygems.org' 
gem "omniauth", "0.2.0" 
gem "fb_graph" 
gem 'rails', '>=3.0.6' 
gem 'mysql2' 
gem "delayed_job" 
gem "rvm" 
gem "whenever" 
gem "less" 
gem "bcrypt-ruby", :require => "bcrypt" 
gem "twitter" 
gem "paperclip" 
gem "aws-s3" 
gem "RedCloth" 
gem "decent_exposure", :git => "git://github.com/voxdolo/decent_exposure.git" 
# Application monitoring services 
gem 'hoptoad_notifier', ">=2.4.5" 
gem "newrelic_rpm", ">=2.13.4" 
gem "yahoo-weather", "1.2.0", :require => false 
gem "json", "~>1.4.6" 
gem 'will_paginate', :git => "git://github.com/mislav/will_paginate.git", :branch => "rails3" 
gem 'acts-as-taggable-on' 
gem "aasm", ">=2.2.0", :require => "aasm" 
gem 'thinking-sphinx', '2.0.2', :require => 'thinking_sphinx' 
# These gems are not required on the Staging/Production server 
group :development, :test do 
  gem 'capistrano' 
  gem "capistrano-ext" 
  gem "nifty-generators" 
  gem 'factory_girl_rails', :git => "http://github.com/CodeMonkeySteve/factory_girl_rails.git" 
  # Keep on top of the latest RSpec Gems 
  gem "rspec-rails",        :git => "git://github.com/rspec/rspec-rails.git" 
  gem "rspec",              :git => "git://github.com/rspec/rspec.git" 
  gem "rspec-core",         :git => "git://github.com/rspec/rspec-core.git" 
  gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git" 
  gem "rspec-mocks",        :git => "git://github.com/rspec/rspec-mocks.git" 
  gem 'shoulda' 
  gem "mocha" 
  # gives us the mock_model method for mocha 
  gem 'rspec-rails-mocha', '~> 0.3.0' 
  gem "faker" 
  gem "autotest", ">=4.4.6" 
  gem "autotest-growl" 
  gem "autotest-rails" 
  gem "database_cleaner" 
  gem "redgreen" 
  gem "launchy" 
  gem "faker" 
  gem 'ruby-debug' 
  gem "rcov" 
  gem "rdoc" 
  gem "ruby-prof" 
end

【问题讨论】:

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


    【解决方案1】:

    cache_classes = false 时 aasm 会很快泄漏内存(这是开发模式下的默认设置)。你确实使用了很多宝石,但我敢打赌,这背后是 aasm。

    正如其他人所说,最好使用内存分析器。

    【讨论】:

      【解决方案2】:

      看起来你有一些内存泄漏。尝试使用内存分析器:https://github.com/ice799/memprof

      【讨论】:

      • 谢谢 - 我已经检查了 memprof,但是当我尝试加载它时出现错误:Magic for Ruby Mach-O 文件不匹配
      • 请尝试从github安装,我是这样安装的。混帐克隆github.com/ice799/memprof.git; gem 构建 memprof.gemspec; sudo gem install memprof-*.gem ;告诉我它是否适合你。
      • 感谢 Roman,但仍然没有运气 :( 我注意到当我将 cache_classes 设置为“true”时问题就不那么严重了。谁能给我一些关于如何在没有 memprof 的情况下找到泄漏的指示?
      【解决方案3】:

      检查 config/newrelic.yml 是否:

      developer_mode: false|true
      

      如果设置为“true”,那么内存问题可能就是这样。

      【讨论】:

      • 阿赫特!好的,所以在 newrelic.yml 中将 developer_mode 设置为 true 但是更改它并重新启动仍然没有太大帮助。 RSS 仍然随着每个请求而攀升。
      • 只在开发中泄漏内存?您可能有一些 gem(ruby-prof?)来收集内存中的数据。看看如何确定谁对内存泄漏负责:guides.rubyonrails.org/…
      • 它在开发模式和生产模式下都在泄漏内存......但在开发模式下肯定会更严重。模式。
      • github.com/rubyist/aasm/issues/31 - aasm gem 似乎有内存问题,尝试禁用它,看看它在没有它的情况下如何执行。
      猜你喜欢
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      相关资源
      最近更新 更多