cucumber - Why is the first Rails request extremely slow in testing? -
in ruby on rails, when run rails server, first request seems extremely slow, logs show slowness comes 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 needs connect database. next request 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 has cache, , has database connection. i've tried restart server, restart database, clear browser cache , rake db:sessions:clear
, unable first request go slow again in development.
here's things interesting. every single time run cucumber tests, first request incredibly slow:
2017-08-14 11:19:52.879 [ 27729] [info ] completed 200 ok in 38326ms (views: 38306.8ms | activerecord: 6.1ms)
it's longer in development unknown reasons.
what different between restarting rails server , re-running test makes first request of tests slow? steps can take troubleshoot such issue?
(it's no fun waiting 30 seconds every time want run 1 of our cucumber tests)
unfortunately answer extremely isolated our code, wanted share answer in-case else ever ran situation.
i noticed if ran rake tmp:cache:clear
first request in browser slow again. investigated command , saw cleared out #{rails.root}/tmp
directory.
i found line in cucumber env.rb
:
dir.foreach("#{rails.root}/tmp") { |f| fileutils.rm_rf("#{rails.root}/tmp/#{f}") }
that appeared culprit entire time. don't know why added (3 years ago...)
Comments
Post a Comment