Reputation: 9895
In Ruby on Rails, when I run the rails server, the very first request seems to be extremely slow, the logs show that the slowness comes from the view rendering:
2017-08-14 10:24:12.707 [ 22139] [INFO ] Completed 200 OK in 18547ms (Views: 18501.6ms | ActiveRecord: 3.7ms)
I assume it's because it needs to connect to the database. The next request is of course, fast(er):
2017-08-14 11:01:54.937 [ 25662] [INFO ] Completed 200 OK in 765ms (Views: 714.0ms | ActiveRecord: 8.3ms)
I assume this has something to do with the cache, and it already has a database connection. I've tried to restart my server, restart the database, clear my browser cache and rake db:sessions:clear
, but I am unable to get the first request to go slow again in development.
Here's where things get interesting. Every single time I run the cucumber tests, the very first request is always incredibly slow:
2017-08-14 11:19:52.879 [ 27729] [INFO ] Completed 200 OK in 38326ms (Views: 38306.8ms | ActiveRecord: 6.1ms)
It's even longer than it is in development for unknown reasons.
What is different between restarting the Rails server and re-running a test that makes the first request of the tests so slow? What steps can I take to troubleshoot such an issue?
(It's no fun waiting 30 seconds every time we want to run one of our cucumber tests)
Upvotes: 3
Views: 515
Reputation: 9895
Unfortunately the answer was extremely isolated to our code, but I wanted to share the answer in-case anyone else ever ran into this situation.
I noticed that if I ran rake tmp:cache:clear
the first request in the browser would be really slow again. I investigated that command and saw it cleared out the #{Rails.root}/tmp
directory.
I then found this line in the Cucumber env.rb
:
Dir.foreach("#{Rails.root}/tmp") { |f|
FileUtils.rm_rf("#{Rails.root}/tmp/#{f}")
}
That appeared to be the culprit the entire time. I don't know why that was added (3 years ago...)
Upvotes: 2