Reducing Ruby memory footprint
Topics: Ruby, Ruby on Rails
These tips target memory bloat in Ruby, Sidekiq, and Rails applications.
The problem is related to Ruby threads and how memory allocation works at low-level. In many cases, it’s not a memory leak but memory bloat.
For Sidekiq, reduce the number of Sidekiq threads (e.g. use 10 threads instead of 25)
For Rails applications, set the environment variable MALLOC_ARENA_MAX=2 for tuning glibc memory behaviour.
Heroku sets that variable automatically, and this approach is also recommended by both the creator of Sidekiq and the maintainer of Puma.