Rails - erratic Timeout errors possibly tied to asset compilation Rails - erratic Timeout errors possibly tied to asset compilation angularjs angularjs

Rails - erratic Timeout errors possibly tied to asset compilation


There are a number of ways to debug this. To start, increase the Rack::Timeout time to 25 seconds — while this might seem like it's going to make matters worse, it will allow you to accurately assess the actual time the request is taking (5.1s is a different story than 25s).

Instrument a monitoring tool like NewRelic or Skylight. The former is more popular and can be easily configured to log traces on all requests over a certain threshold. This will allow you to see (roughly) where the time is being spent, as well as parameters/request information that relates to it.

If you think that the requests that are failing are to assets, I would double check that you have asset compilation turned off in production. You want this in production.rb:

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

This means that you need to make every asset you're serving precompile. You can test that your setup is correct by running rake assets:precompile and verifying that the output in public/assets is what you're anticipating.

Make sure you're also outputting logs somewhere you can access them later — I prefer Papertrail, but there are undoubtedly others. This will allow you to find errors when they occur, especially 404s (which is what you'll see if you have requests for assets that are not precompiled). Once you isolate and resolve the issue you can lower this, but I still wouldn't set it lower than 15s.

Garbage collection is another potential culprit for intermittently long request times, though 5 seconds is probably excessive. Newer versions of Ruby (notably, 2.2) are better about managing this, so if you can bump the version you're using that might improve things.

Good luck!