Skip to content

Draft: Set RUBY_GC_HEAP_INIT_SLOTS by default

Matthias Käppler requested to merge mk-set-ruby-gc-init-slots into master

Note: This should be the last step in gitlab-com/gl-infra/production#3680 (closed)

What does this MR do?

Our application is memory heavy and allocates a lot of long-lived objects during boot, since Puma/Rails preload the application. We measured the required heap slots to be just under 3M, and found that sizing the heap accordingly comes with a reduction in memory use and decrease in start-up time, since the GC has less work to do and allocates fewer heap pages upfront.

For now this is meant to apply to Puma only; we are not targeting Sidekiq yet.

Related issues

gitlab#289838 (closed)

Test plan

There are two things we should verify.

  1. That RUBY_GC_HEAP_INIT_SLOTS=3000000 is set for Puma.
  2. That we did not drop any other env vars, since we made a change to how all env vars are dealt with for Puma.

So we should verify that compared to an older build, the only difference is the addition of the new env var.

Reference: Omnibus nightly

Using dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ee:13.9.0-ee.0:

root@local:/# xargs -0 -L1 -a /proc/$(pgrep -f 'puma 5')/environ
PWD=/opt/gitlab/sv/puma
prometheus_run_dir=/dev/shm/gitlab/puma
SHLVL=0
LD_PRELOAD=/opt/gitlab/embedded/lib/libjemalloc.so
ICU_DATA=/opt/gitlab/embedded/share/icu/current
EXECJS_RUNTIME=Disabled
SIDEKIQ_MEMORY_KILLER_MAX_RSS=2000000
TZ=:/etc/localtime
HOME=/var/opt/gitlab
RAILS_ENV=production
GITLAB_CHAOS_SECRET=allow
BUNDLE_GEMFILE=/opt/gitlab/embedded/service/gitlab-rails/Gemfile
PUMA_SKIP_CLUSTER_VALIDATION=true
PATH=/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin
PYTHONPATH=/opt/gitlab/embedded/lib/python3.7/site-packages
GID=998
UID=998
prometheus_multiproc_dir=/dev/shm/gitlab/puma

This branch

root@local:/# xargs -0 -L1 -a /proc/$(pgrep -f 'puma 5')/environ
PWD=/opt/gitlab/sv/puma
prometheus_run_dir=/dev/shm/gitlab/puma
SHLVL=0
LD_PRELOAD=/opt/gitlab/embedded/lib/libjemalloc.so
ICU_DATA=/opt/gitlab/embedded/share/icu/current
EXECJS_RUNTIME=Disabled
SIDEKIQ_MEMORY_KILLER_MAX_RSS=2000000
TZ=:/etc/localtime
HOME=/var/opt/gitlab
RAILS_ENV=production
GITLAB_CHAOS_SECRET=allow
BUNDLE_GEMFILE=/opt/gitlab/embedded/service/gitlab-rails/Gemfile
PUMA_SKIP_CLUSTER_VALIDATION=true
PATH=/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin
RUBY_GC_HEAP_INIT_SLOTS=3000000
PYTHONPATH=/opt/gitlab/embedded/lib/python3.7/site-packages
GID=998
UID=998
prometheus_multiproc_dir=/dev/shm/gitlab/puma

Diff

$ diff /tmp/main.env /tmp/branch.env
14a15
> RUBY_GC_HEAP_INIT_SLOTS=3000000

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com
  • Pipeline is green on dev.gitlab.org if the change is touching anything besides documentation or internal cookbooks
  • trigger-package has a green pipeline running against latest commit

Expected (please provide an explanation if not completing)

Edited by Matthias Käppler

Merge request reports