3
votes

The first request to my rails app is extremely slow in all environments.

This should not be due different way of caching/loading gems. It was fine two hours ago and no major changes are made.

What I did the hours before I noticed my app turned slow:

  • I messed around in production.rb (NOT in development.rb): I was playing around with config.serve_static_assets = true

  • I did a bunch of tasks to diagnose why asset pipeline did not load my stylesheets and images in production (like rake assets:precompile RAILS_ENV=production and rake:clean assets:precompile).

Afterwards I obviously tried to undo all the changes I made, but for some reason my app is now slow in development, while it was perfectly fine before.

How can I fix this?

Thanks in advance :-)

UPDATE 1

When I send a request for localhost:3000, only after 12-13 seconds I receive: Started GET "/" for ::1 at random time

Rendering behaving is normal. All requests after the first one are fine.

UPDATE 2

In an older version of my application I did the following:

  • Replace the old 'app'-folder with the newer one
  • Replace the old 'db'-files with the newer one
  • Replace the old 'config'-files with the newer one

Everything is running smoothly and still have no clue as to what was wrong in the first place. Please note that the version of the app from yesterday still runs slow, so this is not a non-rails related issue.

2
Do you use a version control software like git?spickermann
I messed up, I haven't used it in a while. So that's not a preferable solution.ysr1991
Trying things like Rack-mini-profiler - could it help? Or you assume the request processing starts after long period, not that it takes long period?Pavel Bulanov
This is not a page specific issue, all pages are slow if it is the first request made. While this was not the case before.ysr1991
Anything interesting in the logs of your rails application?pmichna

2 Answers

0
votes

Answer

In production on localhost somehow my assets aren't served up (while they do appear in the public directory after a precompile).

In production.rb: config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? was changed to: config.serve_static_files = true or even config.serve_static_assets = true.

This also slows the first request down in a development environment apparently

-1
votes

I have this problem too, and i found bottleneck. Problem in realization OpenSSL::Random.random_bytes on Windows (see this: https://github.com/rails/rails/issues/25805). It used for cookies.

I wrote this solution for my debug machine. But this is very dangerous and not must be used in production

module OpenSSL
  module Random
    def self.random_bytes(length)
      ::Random.new.bytes(length)
    end
  end
end