3

Does anyone have any experience with Rail development page display erratically slowing down and speeding up (page appears 15-20 seconds after the console says the entire page has been rendered).

My development environment is rails 3.0.17 on Mac (Lion), WEBrick 1.3.1, ruby 1.9.2, with Postgres v11 (app supplied by Heroku) for the development database.

Recently, I've noticed some very long delays loading pages... 15 to 20 seconds at times, and the delay is completely unrelated to the complexity of the page, and a given page might load fast several times, then load slow. It might be pretty bad for several minutes, then go away for an hour.

And whether the page loads slow or fast, the rails log always shows the page has rendered fairly quickly... I'll see something like "Completed 200 OK in 486ms" but then the browser might say "waiting for localhost" for another 15 seconds before displaying the page.

Does not seem to depend on the browser (FF or Safari act the same).

Dos not sem to relate to updating the code base. I cna be testing some UI elements and everything is snappy, then suddenly several pages hang for 15-120 seconds.

Still happens even after I added the gem 'rails-dev-boost' to my Gemfile in development.

I also added to my development machine gem 'http_logger' to log calls to external http requests like S3, but don't see that as a factor (the delays often happen on pages that don't access external APIs).

My layouts have a couple of external .js dependencies such as http://static.twilio.com/libs/twiliojs/1.0/twilio.min.js, but I have added that to the bottom of my layout so I would (resumably) still see the page contents quickly if that were being delayed. (Besides, it is probably cached by my browser).

Of course I have tried rebooting the machine, verified activity monitor seems normal for CPU and memory usage. It does not seem to correlate when timemachine is doing its thing.

MORE INFO: per suggestion in comment from AKG below, I used Firebug's web console and most of the time the stylesheets load in a couple of milliseocnds, but when the slowdown occurs I'm seeing delays of 8-20 seconds for most of the stylesheets... which suggests webrick is failing to serve the pages timely?

jpw
  • 18,697
  • 25
  • 111
  • 187
  • Open it up in chrome and look at the inspector (out dev console, or whatever you call the thing you get with cmd-opt-i) and hit the network tab. What do you see going on there? – Amit Kumar Gupta Dec 31 '12 at 06:57
  • good tip - I used the firebug web console for firefox, and sure enough SOME times it's showing 8-20 second response times for the stylesheets, and sometimes it's very fast (a few milliseconds). I'm using 3.0,17, so it's not an asset pipeline issue. Cannot image why some of the project stylesheets would erratically load so slowly? – jpw Dec 31 '12 at 07:31
  • Can't imagine why stylesheets would take 20s to load, how big are they? As for the high variance, it might be a caching thing. The browser probably caches the stylesheets for a period of time, during which load times will be fast; once the cache expires it will have to refetch the stylesheets, which will take longer (although I still can't explain the 20s). Try fiddling with your browser's caching settings. – Amit Kumar Gupta Dec 31 '12 at 09:44
  • That's not it... thy are not big, and it can happen even if the same page is re-loaded multiple times. – jpw Dec 31 '12 at 23:07
  • Did you use subdomains for your project, i had the same problem, please take a look at this thread http://stackoverflow.com/questions/9720572/slow-assets-ruby-1-9-3-macos-rails-3-2 – Mikhail Nikalyukin Oct 07 '13 at 07:39

2 Answers2

2

It could be that buggy/slow middleware is executing after the render is called, but before the response is sent. I recently ran into this issue with pauses of more than 1 minute in some cases, and the culprit turned out to be the Bullet gem, which is designed to help us detect N+1 queries. I removed the middleware and the issue went away!

fgagnon
  • 21
  • 2
  • This was the exact fix for me! I had a complex query, and I guess Bullet wasn't able to handle it. Disabling Bullet resolved the issue. – stephen.hanson May 16 '17 at 17:25
0

I got the same problem a few times. I switched to Mongrel. That automatically resolved the issue. However, I got this with Rails 2.3.8.

Learn More
  • 1,535
  • 4
  • 29
  • 51