Last active
August 20, 2018 20:46
-
-
Save austra/13c343791a42d69c09f64c0c0af00439 to your computer and use it in GitHub Desktop.
Jemalloc Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We tried this about a year or so ago. We didn't see any memory or performance savings at the time, but I'm not sure about our methodology... | |
Eveything I've read about this indicates decent to great memory/peformance gains: | |
(Nate Berkopec is big in the Rails perfomance game, and recommends everyone use it.) | |
https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html | |
Other good writeups: | |
http://engineering.appfolio.com/appfolio-engineering/2018/2/1/benchmarking-rubys-heap-malloc-tcmalloc-jemalloc | |
https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/ | |
https://medium.com/@adrienjarthon/ruby-jemalloc-results-for-updown-io-d3fb2d32f67f | |
https://brandonhilkert.com/blog/reducing-sidekiq-memory-usage-with-jemalloc/ | |
Installation: | |
We were trying a much harder installation at the time... Compiling ruby with jemalloc. We should be able to simply: | |
sudo apt-get install libjemalloc-dev | |
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1 rails s puma | |
If you run with MALLOC_CONF=stats_print:true you get lots of fun stats after ending the process, which also confirms your ruby is using jemalloc. | |
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1 MALLOC_CONF=stats_print:true irb | |
For our legacy environments, or to install with jemalloc compilied into ruby: | |
- rvm install 2.4.0-jem -C --with-jemalloc (I named mine 2.4.0-jem, but it can just be ruby version) | |
- This command should show -ljemalloc after | |
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']" | |
-lpthread -ljemalloc -lgmp -ldl -lcrypt -lm | |
- This command will also verify | |
MALLOC_CONF=stats_print:true irb | |
on irb `exit` | |
we should see `___ Begin jemalloc statistics ___` | |
Jemalloc details: | |
https://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment