際際滷

際際滷Share a Scribd company logo
Visual representations of
memory issues in Ruby
and Rails
Camille Baldock, @camille_
Memory leaks in Ruby applications
Memory leaks in Ruby applications
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
!
Con鍖guring Oink
 Rails.application.middleware.use( Oink::Middlew
are, :instruments => :memory )
!
 Rails.application.middleware.use( Oink::Middlew
are, :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.鍖nd_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

More Related Content

Memory leaks in Ruby applications