我目前正在开发一个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
592888 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运行REEruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]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
当cache_classes = false
(这是开发模式中的默认值)时,aasm会非常快地泄漏内存。你确实用了很多宝石,但我敢打赌aasm是幕后黑手。
看起来您有一些内存泄漏。尝试使用内存分析器:https://github.com/ice799/memprof
检查config/newrelic。yml:
developer_mode: false|true
如果设置为"true",那么内存问题可能是这样的