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