More Related Content Similar to Debugging and Profiling Rails Application (20) More from David Paluy (15) Debugging and Profiling Rails Application4. Agenda
● “Winter is coming!”
● Garbage Collector
● Debug Tools
● Profiling Tools
7. How Ruby Works?
Physical RAM
Process Heap
Ruby Heap Ruby Heap
Ruby Ruby Ruby Ruby Ruby Ruby
Object Object Object Object Object Object
12. GC Process
● GC finds non-reachable objects and adds
them to Free List
● If Free List is still empty, another Heap
allocated
13. MRI GC
● “Conservative”: any bit pattern could be a
pointer (may produce false positive)
● “Stop the world”: no other Ruby code can
execute during GC
● “Mark & Sweep”:
mark all objects in use, than sweep away
unmarked objects
16. How to Debug?
● gem "pry-debugger"
https://github.com/nixme/pry-debugger
● gem "debugger-pry"
https://github.com/pry/debugger-pry
17. Tools
● ObjectSpace.count_objects
● GC debug - Enable heap dump support
● gdb.rb (only Linux)
Note: memprof works only with Ruby 1.8
19. Enable heap dump support to Ruby
Install custom patched version of ruby
Usage:
22. Profiling Tools
● Ruby Benchmark
● ruby-prof
● perftools.rb (Google perftools for Ruby)
23. Benchmark
● gem 'benchmark_suite'
https://github.com/evanphx/benchmark_suite
25. ruby-prof Measurements
● process time (RubyProf::PROCESS_TIME)
● wall time (RubyProf::WALL_TIME)
● cpu time (RubyProf::CPU_TIME)
● object allocations (RubyProf::ALLOCATIONS)
● memory usage (RubyProf::MEMORY)
● garbage collections runs (RubyProf::GC_RUNS)
● garbage collection time (RubyProf::GC_TIME)
29. Summary
● More Objects => Longer GC => Slow
● Examine your HEAP
● Use Tools