Skip to content

Instantly share code, notes, and snippets.

@ThomasLeister
Last active April 10, 2023 01:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasLeister/64a8ff3e86574aafb29bf6653633894c to your computer and use it in GitHub Desktop.
Save ThomasLeister/64a8ff3e86574aafb29bf6653633894c to your computer and use it in GitHub Desktop.
How to install jemalloc and save RAM on your Mastodon instance
### If you set up your Mastodon instance before 9th of June 2018, you probably
### might not have jemalloc active on your Ruby setup. Jemalloc changes the way Ruby
### allocates memory and saves up RAM. On my 140 users instance RAM usage dropped by 300 MB just by using jemalloc.
### This is how to set it up on Debian 9 Stretch:
### As root, install libjemalloc-dev:
apt install libjemalloc-dev
### Change to mastodon user:
su - mastodon
### Check your active ruby version and if there maybe is a new version recommended in the Mastodon Production Guide:
### https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Production-guide.md#dependencies-that-need-to-be-added-as-a-non-root-user
### (see rbenv install command). At the time of writing my server was running on Ruby 2.5.0, but version 2.5.1
### was recommended. Therefore I did not recompile the old Ruby version, but the new one instead:
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.5.1
### Make sure you're on the latest Ruby version:
rbenv global 2.5.1
### Leave mastodon user and restart all the services:
exit
systemctl restart mastodon-sidekiq
systemctl restart mastodon-streaming
systemctl restart mastodon-web
### DONE!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment