From Bloat to Sleek: A Rails Memory Tale With Jemalloc

In my previous blog we tried to analyze what could be the reason behind a Rails app hogging so much memory. Now there are multiple ways to approach this issue from fixing N 1 queries to profiling shady APIs and debugging them, my most fruitful discovery was a shift to a memory allocator named jemalloc.This term kept popping up, and, initially, it was a complete enigma to me.Memory Surges in Multi-Threaded EnvironmentAs mentioned in my previous post, we also migrated to Puma from Unicorn during the K8s migration. Now Unicorn is single-threaded while we started running Puma with 5 threads in production and boom, the memory usage skyrocketed.This happens due to something called per-thread memory arenas in the default glibc malloc. While I won't delve deep into the intricacies this post by Nate Berkopec does it beautifully.
From Bloat to Sleek: A Rails Memory Tale With Jemalloc #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/from-bloat-to-sleek-a-rails-memory-tale-with-jemalloc

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles