Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angelina Ballerina Learns about Memory Allocation

Angelina Ballerina Learns about Memory Allocation

Memory issues can be a black box often thrown over the fence for the most senior level developers to solve. For newer developers it seems like all of a sudden, your app is failing and you're seeing red everywhere. You've optimized your database queries but are still running into issues. What does this all mean? How do you figure out what's going on without solely passing it off to someone else? You'll walk away from this talk with an understanding of what memory allocation means and the tools you can use to assess what's happening.

Presented at Curry on Conf 2017 and Strange Loop 2017

Allison McMillan

June 20, 2017
Tweet

More Decks by Allison McMillan

Other Decks in Technology

Transcript

  1. Angelina Ballerina Learns
    about Memory Allocation
    Allison McMillan
    @allie_p

    View Slide

  2. https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations/memory-game/a/intro-to-memory

    View Slide

  3. Photo: Getty Images

    View Slide

  4. BRYAN WOOLSTON / Reuters
    MinnPost illustration by Jaime Anderson
    http://www.clotureclub.com/2013/07/22-things-most-dc-people-do/

    View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. https://www.youtube.com/watch?v=GFfGzNXnJE8

    View Slide

  11. https://digiday.com/marketing/the-new-face-of-programmatic-efficacy-over-efficiency/

    View Slide

  12. View Slide

  13. First Seek to Understand
    - Stephen Covey

    View Slide

  14. http://www.buzinga.com.au/buzz/app-development-jargon-glossary/

    View Slide

  15. http://blackgeekygirl.deviantart.com/art/Little-Miss-Smartypants-515026930

    View Slide

  16. Definitions
    Scenarios
    Concepts
    Tools

    View Slide

  17. https://www.goodreads.com/book/show/492812.Angelina_Ballerina

    View Slide

  18. http://bookinwithbingo.blogspot.com/2011/04/

    View Slide

  19. View Slide

  20. https://www.pinterest.com

    View Slide

  21. View Slide

  22. View Slide

  23. http://www.wikihow.com/Find-Your-Own-Dancing-Style

    View Slide

  24. www.pinterest.com

    View Slide

  25. https://www.pinterest.com/pin/497507090057749846/

    View Slide

  26. https://s-media-cache-ak0.pinimg.com/originals/01/69/1a/01691a66976f8e035a34990fb63e22de.jpg

    View Slide

  27. http://www.vashtie.com/culture/disneys-aladdin-still-us-dreaming-three-wishes/

    View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. https://giphy.com/gifs/jecamartinez-ballet-ballerina-tippy-toes-yoJC2K2zjyPhKzg8lq

    View Slide

  32. http://gifsgallery.com/angelina+ballerina+gif

    View Slide

  33. https://giphy.com/gifs/loop-ballet-perfection-Ez1XmttaHzjQ4

    View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. https://www.pinterest.com/pin/766245324070166230/

    View Slide

  40. Memory
    Can I have a box?

    View Slide

  41. +
    Memory

    View Slide

  42. Heap
    Stack

    View Slide

  43. Stack
    Clean room
    Help with
    dinner
    Do a chore

    View Slide

  44. Heap

    View Slide

  45. http://code.chaoscreated.com/

    View Slide

  46. Heap
    Turn
    Position
    Technique

    View Slide

  47. Heap
    Machine
    Heap
    Ruby
    Heap

    View Slide

  48. Heap
    Dance Heap
    Ballet
    Heap

    View Slide

  49. Heap
    Dance Heap
    Ballet Heap
    Page Page
    Page

    View Slide

  50. Heap
    Machine Heap
    Ruby Heap
    Page
    Node/Slot
    Ruby Object

    View Slide

  51. Heap
    Dance Heap
    Ballet Heap
    Feet Positions
    Node/Slot
    First
    position
    Node/Slot
    Fourth
    position
    https://dancer.com/ballet-info/in-the-studio/terms-positions/

    View Slide

  52. Open slot

    View Slide

  53. new first open slot
    Bump Pointer Allocation

    View Slide

  54. Eden page
    Retained objects

    View Slide

  55. http://artandpractice.blogspot.nl/2013/04/huma-1315-chapter-8-dance.html
    new
    memory

    View Slide

  56. View Slide

  57. View Slide

  58. View Slide

  59. Garbage collection is a type of
    automatic memory
    management that makes a
    program seem like it has
    infinite memory by reclaiming
    objects that are no longer in
    use.

    View Slide

  60. www.youtube.com

    View Slide

  61. https://alchetron.com/John-McCarthy-(computer-scientist)-1012892-W

    View Slide

  62. http://imgur.com/gallery/btPUV

    View Slide

  63. https://giphy.com/gifs/cheezburger-funny-amazing-76D0WNoMfMOyc

    View Slide

  64. https://en.wikipedia.org/wiki/Box_Step

    View Slide

  65. http://makeagif.com/gif/stanford-viennese-ball-2013-opening-committee-waltz-cH-YJy

    View Slide

  66. Heap

    View Slide

  67. Heap

    View Slide

  68. Heap

    View Slide

  69. Object Graph
    Heap
    object
    Root
    References
    References
    Heap
    object
    Heap
    object

    View Slide

  70. http://classicalballetnews.com/how-to-releve-in-ballet-video/how-to-releve-in-ballet/

    View Slide

  71. Stack
    Clean room
    Help with
    dinner
    Do a chore
    Angelina, Clean your room

    View Slide

  72. Ballet Heap
    Page

    View Slide

  73. https://www.tumblr.com/search/ballet%20perfection

    View Slide

  74. Granule
    Chunk
    Lists

    View Slide

  75. Slot
    Slot
    Slot
    Slot

    View Slide

  76. Slot
    Slot
    Slot
    Slot
    r value

    View Slide

  77. https://speakerdeck.com/pat_shaughnessy/visualizing-garbage-collection-in-rubinius-jruby-and-ruby-2-dot-0

    View Slide

  78. “first position”
    class: Position
    Object: position1 = Position.new

    View Slide

  79. Object: position1 = Position.new Address

    View Slide

  80. View Slide

  81. Program Footprint

    View Slide

  82. https://www.pinterest.com

    View Slide

  83. Object
    Space

    View Slide

  84. Mutator
    Collector

    View Slide

  85. https://hirshhorn.si.edu/kusama/infinity-rooms/

    View Slide

  86. http://gifrific.com/baby-groot-dancing-guardians-of-the-galaxy/

    View Slide

  87. http://www.blu-ray.com/movies/screenshot.php?movieid=44938&position=5

    View Slide

  88. Root

    View Slide

  89. https://www.gutenberg.org/files/27367/27367-h/27367-h.htm
    Root

    View Slide

  90. Root

    View Slide

  91. https://www.americandancesportcenter.com/waltz

    View Slide

  92. http://tech.eu/features/2921/enevo-waste-management-profile/

    View Slide

  93. Root

    View Slide

  94. 1 1
    1
    1
    1
    0 0
    0

    View Slide

  95. 1 1
    1
    1
    1
    0 0
    0

    View Slide

  96. https://pixabay.com/en/playmobil-toy-garbage-collector-771313/

    View Slide

  97. FromSpace
    ToSpace

    View Slide

  98. FromSpace
    ToSpace

    View Slide

  99. Pointer
    FromSpace
    ToSpace

    View Slide

  100. FromSpace (formerly ToSpace)
    ToSpace

    View Slide

  101. FromSpace

    View Slide

  102. Mark
    Sweep
    Compact

    View Slide

  103. Root

    View Slide

  104. Root

    View Slide

  105. Root

    View Slide

  106. Root

    View Slide

  107. Root

    View Slide

  108. Root

    View Slide

  109. https://giphy.com/gifs/dance-black-and-white-dancing-FobM3MLsUVmnu

    View Slide

  110. https://dribbble.com/shots/3588547-Hiplet-Desigual-2

    View Slide

  111. Generation 0
    Generation 1
    Root

    View Slide

  112. Generation 0
    Root

    View Slide

  113. Generation 0
    Root

    View Slide

  114. Generation 0
    Root

    View Slide

  115. Generation 1
    Root

    View Slide

  116. Generation 1
    Generation 0
    Root

    View Slide

  117. Generation 1
    Generation 0
    Root

    View Slide

  118. Generation 1
    Generation 0
    Root

    View Slide

  119. Generation 1
    Generation 0
    Root

    View Slide

  120. Write barrier
    Generation 1
    Generation 0
    Root

    View Slide

  121. Generation 1
    Generation 0
    Root

    View Slide

  122. Dancing with the stars

    View Slide

  123. https://coderwall.com/p/yutdhq/understanding-garbage-collection-p1-2

    View Slide

  124. Root

    View Slide

  125. Root

    View Slide

  126. https://giphy.com/gifs/agentm-agent-m-Xdcj75alQutVe

    View Slide

  127. writer barrier
    Root

    View Slide

  128. https://www.pinterest.com/pin/470626229787955295/

    View Slide

  129. View Slide

  130. View Slide

  131. View Slide

  132. https://i2.wp.com/sassandbalderdash.com/wp-content/uploads/2014/03/letitgo7.gif

    View Slide

  133. Rails
    Apps
    Retained
    Memory
    Allocated
    Memory
    = +

    View Slide

  134. View Slide

  135. http://www.pastposters.com/details.php?prodId=4009

    View Slide

  136. 2.3.1 :001 >
    GC.stat(:total_freed_objects)
    => 97198

    View Slide

  137. http://gifrific.com/uga-mens-swim-and-dive-team-harlem-shake-dance/

    View Slide

  138. {

    :count=>0,

    :heap_allocated_pages=>24,

    :heap_sorted_length=>24,

    :heap_allocatable_pages=>0,

    :heap_available_slots=>9783,

    :heap_live_slots=>7713,

    :heap_free_slots=>2070,

    :heap_final_slots=>0,

    :heap_marked_slots=>0,

    :heap_swept_slots=>0,

    :heap_eden_pages=>24,

    :heap_tomb_pages=>0,

    :total_allocated_pages=>24,

    :total_freed_pages=>0,

    :total_allocated_objects=>7796,

    :total_freed_objects=>83,

    :malloc_increase_bytes=>2389312,

    :malloc_increase_bytes_limit=>16777216,

    :minor_gc_count=>0,

    :major_gc_count=>0,

    :remembered_wb_unprotected_objects=>0,

    :remembered_wb_unprotected_objects_limit=>0,

    :old_objects=>0,

    :old_objects_limit=>0,

    :oldmalloc_increase_bytes=>2389760,

    :oldmalloc_increase_bytes_limit=>16777216

    }

    View Slide

  139. Heap Allocated Pages
    Pages

    View Slide

  140. Heap Sorted Length
    Slots

    View Slide

  141. Heap available slots
    Slots

    View Slide

  142. Heap live slots

    View Slide

  143. Heap Free Slots

    View Slide

  144. Heap Final Slots
    Root

    View Slide

  145. Total Allocated Objects
    Root

    View Slide

  146. Total Freed Objects
    Root

    View Slide

  147. 2.3.1 :001 >
    GC.stat[:count]

    View Slide

  148. GC::Profiler.enable
    10000.times do
    puts “angelina turns”
    end
    GC.start
    puts GC::Profiler.result
    GC::Profiler.disable

    View Slide

  149. Index 1
    Invoke Time(sec) 0.075
    Use Size(byte) 584120
    Total Size(byte) 1207680
    Total Object 30192
    GC Time(ms)
    1.91500000000000003553

    View Slide

  150. > ObjectSpace.each_object

    View Slide

  151. Object
    Space

    View Slide

  152. 2.3.1 :003 > ObjectSpace.count_objects
    =>
    {:TOTAL=>53805, :FREE=>7063, :T_OBJECT=>11
    10, :T_CLASS=>919, :T_MODULE=>42, :T_FLOAT
    =>4, :T_STRING=>28307, :T_REGEXP=>195, :T_
    ARRAY=>5470, :T_HASH=>180, :T_STRUCT=>3, :
    T_BIGNUM=>2, :T_FILE=>12, :T_DATA=>269, :T
    _MATCH=>130, :T_COMPLEX=>1, :T_SYMBOL=>7,
    :T_IMEMO=>5201, :T_NODE=>4842, :T_ICLASS=>
    48}

    View Slide

  153. Derailed Benchmarks
    Memory_profiler
    Rack-mini-profiler
    get_process_mem

    View Slide

  154. http://harlequinblog.com/2016/08/11-signs-youre-a-book-lover-and-should-be-celebrating-national-book-lovers-day/

    View Slide

  155. https://www.emaze.com/@AWZCLQTQ/Rube-Goldberg-Machine

    View Slide

  156. Resources
    http://daydreamsinruby.com/
    memory-resources/

    View Slide

  157. Thank you

    View Slide

  158. @allie_p
    [email protected]
    www.collectiveidea.com
    www.daydreamsinruby.com

    View Slide