EY stacks stable-v7, stable-v6 and stable-v5, above release stable-v5-3.0.61, allow to run Ruby with jemalloc enabled. In many cases this can noticeably reduce the memory consumption of your Rails application.
Introduction
Ruby, by default, uses the default memory allocation algorithm in libc, called malloc. Make no mistake, this is a very good allocator and a sensible default algorithm, and it will very likely remain the default for Ruby.
However, malloc tends to suffer from increased memory fragmentation over time, which results in high memory consumption for Ruby processes. This is especially pronounced for background worker processes like Sidekiq.
How to Enable on EY Cloud
Ruby with jemalloc is available on EY stacks stable-v7 and stable-v6 for all supported Rubies, and stable-v5 for Ruby 2.4, 2.5, and 2.6. It can be enabled by setting the environment variable EY_RUBY_JEMALLOC
to true
.
Here is how to do that step-by-step:
-
[Required for stable-v5 environments only] Navigate to the environment you want to enable Ruby with jemalloc for and ensure the stack version is at least stable-v5-3.0.61, if not, Upgrade the environment. Also make sure that the Ruby version is 2.4 or above, if not you will need to Edit your environment and change the Ruby version, after thorough application testing in a local deployment and EY staging environment.
-
Open the Environment Variables options page.
-
Add the
EY_RUBY_JEMALLOC
variable with the valuetrue
. -
Run an "Apply" on the environment.
- To check if the version sporting jemalloc installed successfully:
- For Ruby 2.4 and 2.5 run:
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
and check for-ljemalloc
in the output. - For Ruby 2.6 and above run:
ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
and check for-ljemalloc
in the output. -
Restart the Ruby processes. This is quickest done through a Deploy, as this will restart all application and background workers on all instances. If you are looking to test a particular worker, then issue a specific monit restart command on the relevant instance.
Attention: Enabling jemalloc for Ruby is a significant change and may have unintended consequences. Always test this on a testing environment before enabling it on production!
In the case of multiple applications deployed into a single environment: As the sole system Ruby installation is used by all applications on an instance, applying this setting to one application will apply to all applications sharing that environment.
If you have further questions regarding this feature, please open a support ticket. We will be glad to help you.
Comments
Article is closed for comments.