After Rails 8 Upgrade, my app has been has been really slow and also getting a lot of downtime errors about every 15 mins


I’m not sure if I have everything setup up correctly for Rails 8 and Fly.io. Do I need to setup Propshaft or something?

Here’s my fly.toml

# fly.toml app configuration file for wherecanwedance

app = "wcwd7"
primary_region = "dfw"
console_command = "/rails/bin/rails console"

[build]

[http_service]
  processes = ["web"]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 2

[[vm]]
  memory = "1gb"
  cpu_kind = "shared"
  cpus = 1

[processes]
  web = "bin/rails server -b 0.0.0.0 -p 8080"
  worker = "bundle exec sidekiq"
  sidekiq = "bundle exec sidekiq"

[deploy]
  release_command = "./bin/rails db:prepare"

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

[checks]
  [checks.status]
    port = 3000
    type = 'http'
    interval = '10s'
    timeout = '3s'
    grace_period = '15s'

Here’s my Dockerfile:

# syntax=docker/dockerfile:1
# check=error=true

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.2.2
FROM ruby:$RUBY_VERSION-slim AS base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler

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

# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development:test" \
    RAILS_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential libpq-dev node-gyp pkg-config python-is-python3 && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install JavaScript dependencies
ARG NODE_VERSION=20.5.1
ARG YARN_VERSION=1.22.19
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    npm install -g yarn@$YARN_VERSION && \
    rm -rf /tmp/node-build-master

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
    bundle exec bootsnap precompile --gemfile

# Install node modules
COPY .yarnrc package.json package-lock.json yarn.lock ./
COPY .yarn/releases/* .yarn/releases/
RUN yarn install --frozen-lockfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN NODE_ENV=production yarn vite build

RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile


# Final stage for app image
FROM base

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

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
    useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
    chown -R 1000:1000 db log storage tmp
USER 1000:1000

# Entrypoint sets up the container.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000

I’m also getting a lot of Vips errors with ActiveStorage, I included a screenshot from Sentry as well.

Thanks in advance!!

Not that I’m aware of. I upgraded my app to Rails 8 without issue. I’m using import map and sqlite3, you are using jsbundler and postgres; but neither of those should be an issue?

I’m also using ActiveStorage with Tigris.

1 Like

Have you seen those VIPS errors before with ActiveStorage? I’m just using Amazon S3 and I did on Rails 7.

Any hunches which files I should check for the site taking so long to load after the upgrade? :pray:t5:

Here’s my production.rb

 require "active_support/core_ext/integer/time"

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  config.cache_classes = true


  config.eager_load = true

  config.action_controller.perform_caching = true
 
 # Needed to get the 404 page to work
  config.consider_all_requests_local = false
  config.action_dispatch.show_exceptions = true
  config.exceptions_app = self.routes
  
  config.public_file_server.enabled = ENV.fetch("RAILS_SERVE_STATIC_FILES") { true }

  config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true
  config.assets.debug = true

  config.active_storage.service = :amazon
  config.active_storage.variant_processor
  config.active_storage.logger = Rails.logger

  config.log_level = :info

  config.log_tags = [ :request_id ]

  config.action_mailer.perform_caching = false

  config.action_mailer.default_url_options = { :host => 'wherecanwedance.com' }  


  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :postmark

config.action_mailer.postmark_settings = {
  api_token: Rails.application.credentials.dig(:postmark, :api_token)
}

    # POSTMARK
    config.action_mailer.smtp_settings = {
      address:              'smtp.postmarkapp.com',
      port:                 587,
      user_name:            Rails.application.credentials.dig(:postmark, :api_token),
      password:             Rails.application.credentials.dig(:postmark, :api_token),
      authentication:       :plain,
    }

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  config.action_mailer.raise_delivery_errors = true

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Don't log any deprecations.
  config.active_support.report_deprecations = true
  config.action_view.preload_links_header = false


  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require "syslog/logger"
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

Unfortunately, no hunches here. My upgrade went smoothly, and I’ve not heard of others experiencing slowdowns, so the only help I can provide here is to help you rule out a number of potential causes.

Is there a new Dockerfile template we should be using or do we continue to refer to the Rails 7 Dockerfile template.

Or are we suppose to create a new machine to deploy on?

Thanks in advance!

Try:

bundle update dockerfile-rails
bin/rails generate dockerfile

This will produce a Rails 8 style Dockerfile customized for your application. You will get options to see the diffs and accept or reject the changes.

You don’t need a new machine. If you are using git, commit all your files, run the command mentioned above, and then fly deploy. If that works, commit the updated files, if not, run git checkout . and rerun fly deploy.

1 Like

ok I got a new Dockerfile from the steps you shared and my deployments are completing consistently now. Thank you!

Unfortunately still getting an pretty bad latency on the site with loading pages.

I don’t see any errors in the server logs. Is there some way to see network lags in Grafana or some other Fly debugging tool?

Have you looked at your logs?

Not directly related to Rails 8, but is your application configured to auto stop (that’s typically the default)? Check your fly.toml. If you are using fly postgres, you may need to do that for your database too: Scale to zero for Postgres Development projects · Fly Docs

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.