Ruby on Rails: Reduce Memory Usage by 22%
ruby on rails
Using Jemalloc
# Use jemalloc with configuration
RUN apt-get install libjemalloc2
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
# 1. Sets a 1-second decay time for dirty pages
# 2. Configures 2 memory arenas to balance performance and memory usage
# 3. Enables a background thread for maintenance tasks to enhance application performance
ENV MALLOC_CONF=dirty_decay_ms:1000,narenas:2,background_thread:true
Less Memory + Faster!
Memory bloating issue reduced by 22% as it plateaus at ~2.9GB instead of ~3.7GB.
The NodeFlair application should also feel faster now as we reduced the response time by 12% (p0.9) and 55% (p0.99).
Reference
- Optimizing your deployment by Fly.io
- Malloc Can Double Multi-threaded Ruby Program Memory Usage by Nate Berkopec
A little about what I do at NodeFlair…
The world today runs on code written by developers that solve the world’s problems and impact lives.
Now, imagine a world where developers get to code at a place where they find purpose in their work. This meaning could translate into drive that pushes boundaries to solve more of the world’s problems.
That’s why at NodeFlair, we make it our mission to improve the world by empowering developers to code() at where they love.