문제

I had a Rails 3.2 Ruby 1.9 app on Heroku which worked fine. I upgrade to Ruby 2.1 and Rails 4.1 and soon started getting memory errors:

Error R14 (Memory quota exceeded)

I set an option in Heroku to show the memory usage. It shows increasing usage over time, but it's not clear why:

source=web.1 dyno=heroku.12... sample#memory_total=514.44MB sample#memory_rss=449.46MB sample#memory_cache=0.52MB sample#memory_swap=64.46MB sample#memory_pgpgin=142709pages sample#memory_pgpgout=27516pages

I looked at the ObjectSpace to see which classes have the most instances and got the following top results:

[Module, 1232], [MIME::Type, 1643], [Regexp, 2334], [Hash, 3002], [Class, 3004], [Proc, 3363], [RubyVM::Env, 3416], [Array, 25436], [RubyVM::InstructionSequence, 26490], [String, 127601]

There seem to be a very large number of Strings, though I'm not sure how many there usually are. I ran ObjectSpace.garbage_collect which reduced the Strings by 47485 instances and also affected the instance count of many other classes, such as :T_ARRAY (-16308) and :T_NODE (-19508).

Does the above mean that String objects are the source of the leak? How should I diagnose it further?

Update:
I installed the Oink gem to get additional memory info, and ran it on a piece of the logs. However, it just shows everything as using up a ton of memory:

-- SUMMARY --
Worst Requests:
70748 KB, statics#home
70748 KB, sections#show
40664 KB, pages#show

It also shows the number of Active Records created:

-- SUMMARY --
Worst Requests:
1569, statics#home
829, sections#show
817, pages#show

So there's a general memory leak, but how can I find it?

도움이 되었습니까?

해결책 2

Removing the new_relic gem 3.7.3 helped for a few days, but then the memory issues re-started. Changing Ruby from 2.1 to 2.0 fixed the issue. It seems Unicorn and Ruby 2.1 don't get along well.

다른 팁

try looking at the oink gem to debug where you're using memory https://rubygems.org/gems/oink in your development environment.

Also look at whether your brining in a db object that has a lot of associated (has-many) db elements to it. They can surprise you at how much memory they consume

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top