hunting down memory leaks in ruby
TRANSCRIPT
![Page 1: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/1.jpg)
Hunting down memory leaks
Sergey Alekseev
![Page 2: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/2.jpg)
Hunting down memory leaks
Sergey Alekseev
![Page 3: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/3.jpg)
What’s a memory leak?
![Page 4: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/4.jpg)
![Page 5: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/5.jpg)
Bloat vs. Leak
![Page 6: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/6.jpg)
![Page 7: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/7.jpg)
Get rid of a memory bloat first
*disable NewRelic developer_modein staging
![Page 8: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/8.jpg)
![Page 9: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/9.jpg)
How to hunt down a leak?
1) Find
2) Destroy
![Page 10: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/10.jpg)
How to find a leak?
First look into https://github.com/ASoftCo/leaky-
gems
![Page 11: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/11.jpg)
The most effective way
Siege + New Relic + Skylight
![Page 12: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/12.jpg)
/action-1 /action-2
![Page 13: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/13.jpg)
New Relic – Transactions
• Most time consuming
• Slowest average response time
• Apdex most dissatisfying
• …
![Page 14: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/14.jpg)
![Page 15: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/15.jpg)
![Page 16: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/16.jpg)
2 types: Ruby & C memory leaks
![Page 17: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/17.jpg)
Ruby memory leaks
• Errno::ENOMEM
• GC.start
• ObjectSpace.count_objects
• ObjectSpace.each_object(String)
• GC.stat
![Page 18: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/18.jpg)
C memory leaks
• Valgrind
• https://lbtwiki.cern.ch/bin/view/Online/Kcachegrind
• Heap dump
![Page 19: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/19.jpg)
![Page 20: Hunting down memory leaks in Ruby](https://reader033.vdocuments.net/reader033/viewer/2022042619/58a6c4901a28abcc458b491f/html5/thumbnails/20.jpg)
Сергей АлексеевRuby developer, Founder @ ASoft.co
• https://github.com/sergey-alekseev
• info @ asoft.co
• http://sergeyalekseev.by/#contacts