From d8636ff0e883e7009ffd0b2882e7018fdc310f13 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 20 Apr 2021 00:54:06 -0700 Subject: [PATCH 1/3] Build ruby with jemalloc This should improve memory usage and test Ruby the way we do in production. --- scripts/install-ruby | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/install-ruby b/scripts/install-ruby index 178bc25..14efd4b 100755 --- a/scripts/install-ruby +++ b/scripts/install-ruby @@ -7,9 +7,26 @@ set -xeou pipefail RUBY_VERSION=${1} RUBY_MAJOR=${1%.*} # strip last component RUBY_DOWNLOAD_SHA256=${2} - RUBY_DOWNLOAD_URL="https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.gz" +JEMALLOC_VERSION=5.2.1 +JEMALLOC_DOWNLOAD_SHA256="34330e5ce276099e2e8950d9335db5a875689a4c6a56751ef3b1d8c537f887f6" +JEMALLOC_DOWNLOAD_URL="https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2" + +# Download jemalloc +mkdir -p /usr/src/jemalloc +cd /usr/src/jemalloc +curl --retry 6 -L -so jemalloc.tar.bz2 ${JEMALLOC_DOWNLOAD_URL} +echo "${JEMALLOC_DOWNLOAD_SHA256} jemalloc.tar.bz2" | sha256sum -c - + +# Install jemalloc +tar -xjf jemalloc.tar.bz2 +rm jemalloc.tar.bz2 +cd jemalloc-${JEMALLOC_VERSION} +./autogen.sh --prefix=/usr --enable-prof +make -j "$(nproc)" install +cd /tmp + # Download Ruby curl -fsSL "$RUBY_DOWNLOAD_URL" -o ruby.tar.gz echo "${RUBY_DOWNLOAD_SHA256} ruby.tar.gz" | sha256sum -c - @@ -38,7 +55,7 @@ if [[ -d "/patches/ruby/$RUBY_VERSION" ]]; then fi # Compile -./configure --enable-shared --disable-install-doc --disable-install-rdoc --disable-install-capi +./configure --enable-shared --with-jemalloc --disable-install-doc --disable-install-rdoc --disable-install-capi make install -j $(nproc) # Cleanup From 7cde6cc615603994a11e2de85f196b06e51d2d37 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 20 Apr 2021 01:14:21 -0700 Subject: [PATCH 2/3] Add autoconf to build --- scripts/install-ruby | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install-ruby b/scripts/install-ruby index 14efd4b..a299571 100755 --- a/scripts/install-ruby +++ b/scripts/install-ruby @@ -13,6 +13,10 @@ JEMALLOC_VERSION=5.2.1 JEMALLOC_DOWNLOAD_SHA256="34330e5ce276099e2e8950d9335db5a875689a4c6a56751ef3b1d8c537f887f6" JEMALLOC_DOWNLOAD_URL="https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2" +# Install needed packages +apt-get update +apt-get install -y --no-install-recommends bison dpkg-dev libgdbm-dev autoconf + # Download jemalloc mkdir -p /usr/src/jemalloc cd /usr/src/jemalloc @@ -36,10 +40,6 @@ mkdir -p /usr/local/etc echo 'install: --no-document' >> /usr/local/etc/gemrc echo 'update: --no-document' >> /usr/local/etc/gemrc -# Install needed packages -apt-get update -apt-get install -y --no-install-recommends bison dpkg-dev libgdbm-dev ruby - # Unpack Ruby mkdir -p /usr/src/ruby tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 From 3391b94d3978969875b4bc7aecb35f315aab2631 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 20 Apr 2021 01:54:15 -0700 Subject: [PATCH 3/3] Clean up jemalloc source dir --- scripts/install-ruby | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-ruby b/scripts/install-ruby index a299571..952cf80 100755 --- a/scripts/install-ruby +++ b/scripts/install-ruby @@ -60,7 +60,7 @@ make install -j $(nproc) # Cleanup cd / -rm -rf /usr/src/ruby +rm -rf /usr/src/ruby /usr/src/jemalloc apt-get purge -y --auto-remove ruby # Verify