~/talk

Halve Your Memory Usage With These 12 Weird Tricks

Talkat RubyConf 2016 · 2016-11-10..11-12· [ruby, ruby-on-rails]
slides:none on file

Claims twelve concrete tricks that can halve your memory usage, targets MRI/C Ruby, and gives numbers: aim for 300 megabytes per instance, expect logarithmic growth and long steady-state windows (12–24+ hours). Explains GC thresholds, object-space pages/408 slots, heap fragmentation, and shows tools that find culprits: Scout/Skylight, oink, memory_profiler, derailed. Presents operational fixes that work in practice: jemalloc (Heroku buildpack), copy-on-write preload with Puma/Unicorn, malloc_arena_max and Minitest/Hell for threading. Results are demonstrable, not just theory.

AI-written summary · about

  1. 0:00Intro
  2. 2:02RUBY IS A GARBAGE COLLECTED LANGUAGE. BUT MY MEMORY IS GROWING. THEREFORE, MEMORY LEAK.
  3. 3:11DIAL BACK THE INSTANCE COUNTS DISCOVER TRUE STEADY-STATE MEMORY USAGE PER INSTANCE
  4. 5:08MYTH: MEMORY USAGE SHOULD LOOK LIKE A LONG, FLAT LINE
  5. 8:57AIM FOR 300MB PER INSTANCE THIS ALSO APPLIES TO SIDEKIQ
  6. 9:38STOP ALLOCATING SO MANY OBJECTS AT ONCE
  7. 9:50MYTH: "SHOULDN'T GC CLEAN THE UNUSED OBJECTS UP AFTER THE JOB COMPLETES?"
  8. 10:10THRESHOLDS HEAP FRAG FREE ISN'T FREE
  9. 10:54THRESHOLDS NOT TIMERS.
  10. 16:39MALLOC AND FREE ARE SUGGESTIONS, NOT COMMANDS
  11. 20:05HEAP FRAGMENTATION CAN CAUSE LONG-TERM SLOW "LEAKS"
  12. 23:44MAKE YOUR OWN: RubyConf OBJECTSPACE & GC.STAT
  13. 24:46SOLUTION 2C: IF ALL ELSE FAILS, MOVE TO RAKE TASKS THROWAWAY VMS ARE BETTER THAN BLOATED VMS
  14. 25:53GEMFILE AUDIT WITH derailed
  15. 26:31MYTH: DEPENDENCIES ARE FREE!
  16. 27:48EMPHASIZES FRAGMENTATION AVOIDANCE AND SCALABLE CONCURRENCY SUPPORT.
  17. 28:34OR --WITH-JEMALLOC
  18. 29:00USE COPY-ON-WRITE PUMA, UNICORN OR PASSENGER W/PRELOADING
  19. 29:22COPY-ON-WRITE Rubycon INCREASES SHARED MEMORY
  20. 32:12USE A THREADED WEBSERVER Punts, Passenger Enterprise. Increase concurrency w/lighter methods
  21. 32:35MINI-MYTH: MY APPLICATION ISN'T THREAD-SAFE
  22. 33:37KEEP RUBY AND GEMS UP-TO-DATE
  23. 33:52RUBY 2.2+ RAILS 4.2+ WATCH OUT FOR RUBY 2.4
  24. 34:45TUNE MALLOC
  25. 36:55mallopt
  26. 37:36GC TUNING CAN FIX: TOO MANY FREE SLOTS SLOW STARTUP TOO MANY OR TOO FEW GCS
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.