diff --git a/Gemfile b/Gemfile index 95f451a..7d14540 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,9 @@ gem "tzinfo-data", platforms: %i[windows jruby] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false +# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/] +gem "thruster", require: false + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index 5c36b72..359dd0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -514,6 +514,11 @@ GEM terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.3.1) + thruster (0.1.8) + thruster (0.1.8-aarch64-linux) + thruster (0.1.8-arm64-darwin) + thruster (0.1.8-x86_64-darwin) + thruster (0.1.8-x86_64-linux) timeout (0.4.1) turbo-rails (2.0.5) actionpack (>= 6.0.0) @@ -595,6 +600,7 @@ DEPENDENCIES sqlite3 (~> 1.4) standard (>= 1.35.1) stimulus-rails + thruster turbo-rails tzinfo-data view_component (~> 3.7) diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 67ef493..57567d6 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -1,7 +1,13 @@ #!/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 [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then +if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then ./bin/rails db:prepare fi diff --git a/bin/thrust b/bin/thrust new file mode 100755 index 0000000..36bde2d --- /dev/null +++ b/bin/thrust @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thruster", "thrust")