I just went through the process of switching our nodejs app to jemalloc, here is how I did it on Debian stretch:
Install jemalloc:
sudo apt-get install libjemalloc-dev
Find the jemalloc binary:
sudo find / -name "*jemalloc*"
Look for a file in a folder like /usr/lib/... ending with .so, for example path could be /usr/lib/x86_64-linux-gnu/libjemalloc.so
Configure server to use jemalloc for all programs:
- Create file with preloading config:
sudo nano /etc/ld.so.preload
- Add the path to the jemalloc binary to the file:
/path/to/jemalloc/binary
- Restart nodejs and check if jemalloc is used, e.g. like this (if jemalloc is used you should see some lines showing the jemalloc binary):
cat /proc/<PID OF NODEJS>/smaps | grep jemalloc
Alternative: Use jemalloc only for nodejs
In bash execute
export LD_PRELOAD=$LD_PRELOAD:/path/to/jemalloc/binary
before starting the nodejs process