Skip to content

Commit

Permalink
Make --jemalloc the default (Rails 8 parity)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jan 5, 2025
1 parent 647e9c1 commit f8842ee
Show file tree
Hide file tree
Showing 53 changed files with 113 additions and 50 deletions.
6 changes: 3 additions & 3 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DockerfileGenerator < Rails::Generators::Base
"compose" => false,
"fullstaq" => false,
"gemfile-updates" => true,
"jemalloc" => false,
"jemalloc" => true,
"label" => {},
"link" => false,
"litefs" => false,
Expand Down Expand Up @@ -996,8 +996,8 @@ def deploy_env
end

if options.jemalloc? && !options.fullstaq?
env["LD_PRELOAD"] = "libjemalloc.so.2"
env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
# env["LD_PRELOAD"] = "libjemalloc.so.2"
# env["MALLOC_CONF"] = "dirty_decay_ms:1000,narenas:2,background_thread:true"
end

if using_puppeteer?
Expand Down
8 changes: 8 additions & 0 deletions lib/generators/templates/docker-entrypoint.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#!/bin/bash -e
<% end -%>

<% if options.jemalloc? -%>
# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

<% end -%>
<% if options.swap && !File.exist?("fly.toml")-%>
<% if run_as_root? or using_passenger? -%>
<% @space = "" -%>
Expand Down
2 changes: 1 addition & 1 deletion test/results/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ FROM base

# Install packages needed for deployment
RUN apk update && \
apk add curl libpq postgresql-client && \
apk add curl jemalloc libpq postgresql-client && \
rm -rf /var/cache/apk/*

# Copy built artifacts: gems, application
Expand Down
6 changes: 6 additions & 0 deletions test/results/alpine/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# If running the rails server then create or migrate existing database
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
./bin/rails db:prepare
Expand Down
2 changes: 1 addition & 1 deletion test/results/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/bin_cd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/bun/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/cache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FROM base
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
Expand Down
2 changes: 1 addition & 1 deletion test/results/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/esbuild/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/execjs_importmap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/execjs_node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/grover/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y chromium chromium-sandbox curl libsqlite3-0 && \
apt-get install --no-install-recommends -y chromium chromium-sandbox curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/idle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libnginx-mod-http-passenger libsqlite3-0 nginx && \
apt-get install --no-install-recommends -y curl libjemalloc2 libnginx-mod-http-passenger libsqlite3-0 nginx && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# configure nginx and passenger
Expand Down
6 changes: 6 additions & 0 deletions test/results/idle/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# allocate swap space
fallocate -l 512M /swapfile
chmod 0600 /swapfile
Expand Down
8 changes: 3 additions & 5 deletions test/results/jemalloc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=xxx
FROM --platform=linux/amd64 ruby:$RUBY_VERSION-slim AS base
FROM ruby:$RUBY_VERSION-slim AS base

# Rails app lives here
WORKDIR /rails
Expand Down Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand All @@ -57,9 +57,7 @@ RUN groupadd --system --gid 1000 rails && \
USER 1000:1000

# Deployment options
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" \
LD_PRELOAD="libjemalloc.so.2" \
MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true"
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
Expand Down
8 changes: 8 additions & 0 deletions test/results/jemalloc/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
./bin/rails db:prepare
fi

exec "${@}"
2 changes: 1 addition & 1 deletion test/results/label/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/litefs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ COPY config/litefs.yml /etc/litefs.yml

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y ca-certificates curl fuse3 libsqlite3-0 sudo && \
apt-get install --no-install-recommends -y ca-certificates curl fuse3 libjemalloc2 libsqlite3-0 sudo && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
6 changes: 6 additions & 0 deletions test/results/litefs/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# mount litefs
sudo -E litefs mount &

Expand Down
2 changes: 1 addition & 1 deletion test/results/litestream/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
6 changes: 6 additions & 0 deletions test/results/litestream/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# If running the rails server then create or migrate existing database
if [ "${@: -5:1}" == "./bin/rake" ] && [ "${@: -4:1}" == litestream:run ] && [ "${@: -3:1}" == "./bin/thrust" ] && [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
./bin/rails db:prepare
Expand Down
2 changes: 1 addition & 1 deletion test/results/minimal/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl default-mysql-client && \
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 nginx ruby-foreman && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 nginx ruby-foreman && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# configure nginx
Expand Down
6 changes: 6 additions & 0 deletions test/results/nginx/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# If running the production procfile then create or migrate existing database
if [ "${@: -3:1}" == "foreman" ] && [ "${@: -2:1}" == "start" ] && [ "${@: -1:1}" == "--procfile=Procfile.prod" ]; then
./bin/rails db:prepare
Expand Down
2 changes: 1 addition & 1 deletion test/results/no_precompiled_gems/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/no_prep/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
6 changes: 6 additions & 0 deletions test/results/no_prep/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# Add any container initialization steps here

exec "${@}"
2 changes: 1 addition & 1 deletion test/results/parallel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/postgresql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl postgresql-client && \
apt-get install --no-install-recommends -y curl libjemalloc2 postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/precompile_defer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN bundle exec bootsnap precompile app/ lib/

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Run and own only the runtime files as a non-root user for security
Expand Down
6 changes: 6 additions & 0 deletions test/results/precompile_defer/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
export LD_PRELOAD
fi

# If running the rails server then create or migrate existing database
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
./bin/rails assets:precompile
Expand Down
2 changes: 1 addition & 1 deletion test/results/private_gemserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/private_gemserver_with_cache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FROM base
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
Expand Down
2 changes: 1 addition & 1 deletion test/results/redis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
2 changes: 1 addition & 1 deletion test/results/rmagick/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl imagemagick libsqlite3-0 && \
apt-get install --no-install-recommends -y curl imagemagick libjemalloc2 libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
Loading

0 comments on commit f8842ee

Please sign in to comment.