memory leaks in ruby applications
DESCRIPTION
Lightning talk about some solutions to finding, preventing memory leaks, churn and bloat. http://camillebaldock.co.uk/memory-leaks-ruby-applications/ Website: http://camillebaldock.co.uk Twitter: @camille_TRANSCRIPT
Visual representations of memory issues in Ruby
and RailsCamille Baldock, @camille_
Bloat
• Memory usage has grown with data set
• Loading too many objects at once
Memory leaks
• Objects that will never be released by the garbage collector
• Objects whose size grows the longer the process runs
Memory churn
• Allocating and deallocating a LOT of objects
• Oink
• Ruby object graphs
• A few best practices…
!
!
Configuring Oink
• Rails.application.middleware.use( Oink::Middleware, :instruments => :memory )
!
• Rails.application.middleware.use( Oink::Middleware, :instruments => :activerecord )
!
• ReportsController#show
• Max heap size: 157524 KB
• Number of AR objects: 14565
Be proactive about
being lazy
Where are the leaks ?
• Look at the object graph in memory !
• ObjectSpace.find_references
• A new ObjectGraph standard library
Journey through the object graph
Counting objects…
Finding something horrible…
!
• status?timestamp=110143244
• status?timestamp=110143245
• ….
Stop using global state !
• Global variables
• Class variables
• Per-process instance state
• …
My app is still slow…
Sources of memory churn
Mutation limits allocation
• Twitter: @camille_
• Github: camilleldn
!
• Conrad Irwin, Object Graph exploration for Ruby memory leaks
• Oink gem, https://github.com/noahd1/oink
• Boston Ruby - Joe Ferris - Memory Issues in Rails