Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
What is jemalloc?. jemalloc (short for Jason Evans malloc) is a high-performance memory allocator that replaces the standard malloc implemented in the glibc standard library. It is used by large projects such as Redis, Firefox, Facebook, and even Android.
Its main advantages:
- Less memory fragmentation
- Better multithreaded performance
- Transparent memory usage logging (via jemalloc profiling)
Why is jemalloc important for Ruby / Rails?
Ruby uses malloc for memory management, especially when working with objects. Under heavy load (for example, multithreaded Puma or Sidekiq), the standard allocator can cause memory fragmentation and slow cleanup.
By replacing malloc with jemalloc, you can achieve:
- Less memory consumption in long-running processes
- More stable RSS (Resident Set Size)
- Potentially faster GC (Garbage Collector), as jemalloc manages object placement better
When does it make sense to enable jemalloc (if you haven't done so yet)?
If you notice that your Ruby / Rails processes are "bloated" in memory after several hours or days of operation β jemalloc can significantly help.
This is especially noticeable on:
- Sidekiq / Resque
- Puma / Unicorn under load
- Services with long-running processes
This post doesn't have any additions from the author yet.