diff --git a/Dockerfile.production b/Dockerfile.production index 80a092f..964309a 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -84,6 +84,16 @@ USER rails:rails ENV RAILS_LOG_TO_STDOUT="1" \ RAILS_SERVE_STATIC_FILES="true" +# Enable jemalloc for better memory performance +# https://fly.io/docs/rails/cookbooks/deploy/#jemalloc +# And enable YJIT for better Ruby performance +# https://fly.io/docs/rails/cookbooks/deploy/#yjit +# +RUN apt-get install libjemalloc2 +ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 \ + MALLOC_CONF=dirty_decay_ms:1000,narenas:2,background_thread:true \ + RUBY_YJIT_ENABLE=1 + # Entrypoint sets up the container. ENTRYPOINT ["/rails/bin/docker-entrypoint"] diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 9dd92e3..2da9ba3 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -2,4 +2,13 @@ # Add any container initialization steps here +# Enable swap https://fly.io/docs/rails/cookbooks/deploy/#enabling-swap +# +fallocate -l 128M /swapfile +chmod 0600 /swapfile +mkswap /swapfile +echo 10 > /proc/sys/vm/swappiness +swapon /swapfile +echo 1 > /proc/sys/vm/overcommit_memory + exec "${@}"