Skip to content

Improve cache hit rates with Rails Bootsnap cache

What does this MR do?

Previously the Bootsnap cache was populated with rake about. While this loads the Rails environment, it does not load a significant amount of the GitLab Rails code.

This merge request adds an intermediate image to populate the Bootsnap cache. It does the following:

  1. Builds gitlab-rails-{ce,ee} image.
  2. Uses docker-compose to spin up a PostgreSQL, Redis, and the Rails image to start gitlab-rails runner.
  3. Builds a gitlab-rails-bootsnap-{ce,ee} image that contains the Bootsnap cache in /srv/gitlab/bootsnap.

Images such as gitlab-webservice-ee then copy the contents of gitlab-rails-bootsnap-ee into their image.

This improves the hit rate significantly. Setting the BOOTSNAP_LOG environment variable shows that previously there were 11,567 and 11,553 "[Bootsnap] miss" messages in webservice and sidekiq, respectively. After this change, the number dropped to 29 and 26, respectively.

More importantly, the startup times dropped about 15 seconds as a result of this change.

Sizes

Debian

Image Size before (GB) Size after (GB)
registry.gitlab.com/gitlab-org/build/cng/gitlab-geo-logcursor 1.72 1.7
registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ce 1.84 1.79
registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ee 1.86 1.84
registry.gitlab.com/gitlab-org/build/cng/gitlab-toolbox-ce 2.04 1.99
registry.gitlab.com/gitlab-org/build/cng/gitlab-toolbox-ee 2.06 2.03
registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ce 1.82 1.77
registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ee 1.84 1.81

UBI-8

Image Size before (GB) Size after (GB)
registry.gitlab.com/gitlab-org/build/cng/gitlab-geo-logcursor 2.62 2.5
registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ee 2.77 2.66
registry.gitlab.com/gitlab-org/build/cng/gitlab-toolbox-ee 2.97 2.85
registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ee 2.74 2.63

Testing

I used this script to validate the size of permissions:

#!/usr/bin/env bash

images=( registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ce
registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ce
registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ee
registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ee
registry.gitlab.com/gitlab-org/build/cng/gitlab-toolbox-ce
registry.gitlab.com/gitlab-org/build/cng/gitlab-toolbox-ee
registry.gitlab.com/gitlab-org/build/cng/gitlab-geo-logcursor )

function pull_and_show () {
    echo "=== Checking $1"
    docker pull -q $1
    docker run $1 sh -c 'ls -al /srv/gitlab/bootsnap; du -hs /srv/gitlab/bootsnap'
    echo "=== Done =="
}

for img in "${images[@]}"
do
    pull_and_show $img:sh-bootsnap-all
    if [[ "$img" != *-ce ]]; then
	pull_and_show $img:sh-bootsnap-all-ubi8
    fi
done

Related issues

Relates to #655 (closed)

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
  • When ready for review, MR is labeled "~workflow::ready for review" per the Distribution MR workflow

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Integration tests added to GitLab QA
  • The impact any change in container size has should be evaluated
  • New dependencies are managed with dependencies.io
Edited by Stan Hu

Merge request reports

Loading