Your SlideShare is downloading. ×
Debugging and Profiling Rails Application
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Debugging and Profiling Rails Application

2,455
views

Published on

Overview of Debugging and Profiling tools for Rails

Overview of Debugging and Profiling tools for Rails

Published in: Self Improvement

2 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,455
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
2
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Debugging and Profiling Rails AppDavid PaluyJanuary 2013
  • 2. Ruby is eating RAM
  • 3. Agenda● “Winter is coming!”● Garbage Collector● Debug Tools● Profiling Tools
  • 4. The Task: Send ~30,000 e-mails
  • 5. Result Before
  • 6. How Ruby Works? Physical RAM Process Heap Ruby Heap Ruby HeapRuby Ruby Ruby Ruby Ruby RubyObject Object Object Object Object Object
  • 7. New Object allocationFree List A L L F O R C E A E T E D
  • 8. New Object allocationFree List A L L O C A T E D
  • 9. New Object allocationFree List is empty A L L O C A T E D
  • 10. New Object allocationFree List is empty – Call GC A L L O C A T E D
  • 11. GC Process● GC finds non-reachable objects and adds them to Free List● If Free List is still empty, another Heap allocated
  • 12. 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
  • 13. More Objects => Longer GC => Slow
  • 14. In our case – Out of Memory!
  • 15. How to Debug?● gem "pry-debugger" https://github.com/nixme/pry-debugger● gem "debugger-pry" https://github.com/pry/debugger-pry
  • 16. Tools● ObjectSpace.count_objects● GC debug - Enable heap dump support● gdb.rb (only Linux) Note: memprof works only with Ruby 1.8
  • 17. ObjectSpace.count_objects
  • 18. Enable heap dump support to RubyInstall custom patched version of rubyUsage:
  • 19. https://github.com/tmm1/gdb.rb Attached to existing process and examine the HEAP
  • 20. Result After
  • 21. Profiling Tools● Ruby Benchmark● ruby-prof● perftools.rb (Google perftools for Ruby)
  • 22. Benchmark● gem benchmark_suite https://github.com/evanphx/benchmark_suite
  • 23. ruby-profgem ruby-profhttps://github.com/rdp/ruby-prof
  • 24. 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)
  • 25. perftools.rbhttps://github.com/tmm1/perftools.rbgem rack-perftools_profiler, :require => rack/perftools_profiler
  • 26. rack-perftools_profiler usage
  • 27. KCacheGrind
  • 28. Summary● More Objects => Longer GC => Slow● Examine your HEAP● Use Tools
  • 29. Q&Ahttp://dpaluy.github.com@dpaluydpaluy@gmail.comhttp://www.linkedin.com/in/davidpaluy