3

I've created a basic demo app in Rails 3.2.2 by using rails new demo. I then had a controller added with a single method which displays a view. It's taking on average 20+ seconds to render the page when I refresh. This obviously makes it impossible to develop, so I'm trying to figure out why and how I can fix this.

I should mention that I'm on a Macbook Air 2011 with 4GB of RAM and the SSD drive so I don't think my hardware has anything to do with the problem.

Running OSX Lion, Rails 3.2.2, & Ruby 1.9.3. Running locally via WEBrick

Update

The only changes I have made are to run rails generator Say hello goodbye.

I then modified the hello.html.erb to say Hello World!

Here is my gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

Started the server by typing rails server

Update 2

Noticed this oddity in the terminal window.. it takes 8 seconds from the starting GET to the GET on the first asset.

Started GET "/say/hello" for 127.0.0.1 at 2012-03-10 22:49:12 -0700
Processing by SayController#hello as HTML
  Rendered say/hello.html.erb within layouts/application (0.1ms)
Completed 200 OK in 5ms (Views: 5.3ms | ActiveRecord: 0.0ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-10 22:49:20 -0700
Served asset /application.css - 200 OK (0ms)

THEN another 4 seconds for the next asset..

Started GET "/assets/say.css?body=1" for 127.0.0.1 at 2012-03-10 22:49:24 -0700
Served asset /say.css - 200 OK (0ms)

UPDATE 3.1

I have traced the problem down to WEBrick. I installed and used thin instead and my calls are very fast as expected. It would still be good to track down what the problem could be in case the WEBrick problem is a symptom of a larger problem..

Community
  • 1
  • 1
Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
  • There's no reason for this to be happening. But without more information this is impossible to debug. Perhaps the code you added, your Gemfile, and what method you used to start your app to start. – Andrew Marshall Mar 11 '12 at 05:38
  • Updated. I have not done anything really. The only out of the ordinary thing I can see is when I run rake about it says my JavaScript Runtime is Node.js (V8) – Shane Courtrille Mar 11 '12 at 05:45
  • Is there anything curious in the logs (`log/development.log`)? Do you have any odd firewall/internet settings? There's no reason this should be that slow, not even the app bootup should be 20 seconds. – Andrew Marshall Mar 11 '12 at 05:50
  • Seeing some really strange timings.. updated. – Shane Courtrille Mar 11 '12 at 05:54
  • No firewall/internet/proxy settings that I can think of (as in I haven't changed a thing) and this is all local... and yeah I had kind of figured this was out of the norm.. I couldn't imagine many people developing under these conditions :D – Shane Courtrille Mar 11 '12 at 05:55
  • created a new app and did rails server. The nice lil intro page takes 16+ seconds to load. – Shane Courtrille Mar 11 '12 at 06:11
  • Could you run the server in production mode as see if the same thing happens, the command is 'rails server -e production' and let me know. – creativetechnologist Mar 11 '12 at 09:17
  • So production mode works.. I reinstalled my machine and it still has the same problem. – Shane Courtrille Mar 12 '12 at 03:12
  • Another Mac-specific issue to consider is whether any of the files you're accessing are quaratined (i.e., `ls -l@` shows `com.apple.quarantine`). That can cause otherwise inexplicable delays in accessing them, and downloaded files are auto-quaratined so it's not uncommon. – blahdiblah Mar 20 '12 at 01:45
  • I'm experiencing the same problem with thin. I just had a page take 1.7 minutes to load in thin. Did you ever figure out what was causing the initial slowdown? – Forrest Mar 28 '12 at 04:25
  • No unfortunately I didn't. Switching to thin fixed everything for me. – Shane Courtrille Mar 28 '12 at 15:13
  • possible duplicate of [Webrick is very slow to respond. How to speed it up?](http://stackoverflow.com/questions/1156759/webrick-is-very-slow-to-respond-how-to-speed-it-up) – Giacomo1968 Nov 18 '14 at 06:42

7 Answers7

3

Not really an answer, but might help isolate the problem:

try a different server like "thin" or "pow" http://pow.cx/ (btw: pow totally rocks!, and consider installing the powder gem which gives nice command-line tools.) Pow is super-easy to install.

Also, check your memory utilization with Activity Monitor app -- 4GB sounds like a lot, but it can get used up really fast. But I am running the same environment and not having the problem.

I don't guess it's an asset compilation issue -- with a squeaky-clean Rails app there's not a whole lot of compiling to be done. But the timings are kind of damning -- maybe check to see what process is chewing up CPU (or maybe disk) during the wait. You can rule out asset pipeline by setting config.assets.enabled = false in your application.rb.

Another thing to check: are you up to the latest ruby 1.9.3 -- I was seeing weird stuff on 1.9.3-p0 and am now using 1.9.3-p125 and all is well.

And another thing to check: use curl or wget from the command line to separately request the page from the assets themselves.

Oh, and do you use Time Machine? My machine sometimes gets very pokey when it's running. Shouldn't be as much of an issue with an SSD, but... who knows.

Tom Harrison
  • 13,533
  • 3
  • 49
  • 77
  • +1 for Pow. If you don't mind giving up port 80, Pow is the best thing to happen to Rails in a long time. – Brandan Mar 20 '12 at 14:07
2

+1 for assets precompilation issue

I will try to answer how you can fix it (i had the same problem until i found this solution):

group :development do
    gem 'rails-dev-tweaks', '~> 0.5.1' #nice gem to speedup development process
end

it helped me a lot

using passenger+nginx for development can be good approach too (for me it speeded up pages rendering approximately for 30-40% against webrick)

hope it helped

okliv
  • 3,909
  • 30
  • 47
  • Tried the dev-tweaks and they don't work. Assets are actually shown in my logs as being 0ms to handle. I should probably have posted a gist.. – Shane Courtrille Mar 15 '12 at 20:01
2

I had a similar problem, but I'm not sure if the solution would apply to you too. My issue was basically related with unneeded reverse lookups. Take a look at this question as it might be of help: Webrick is very slow to respond. How to speed it up?

Community
  • 1
  • 1
Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
1

I theorize that each time some sort of asset compilation or copy is taking place.

I would try changing asset compilation as a test -

In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in config/application.rb by putting this line inside the application class definition: config.assets.enabled = false

I'd be very interest to know if you have any large (or large number of) images or other media assets.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0

WEBrick is doing a reverse DNS lookup on connecting IPs by default. In other words, it's trying to see if your IP address is associated with a domain name. This is unnecessary and takes too long, so you can disable it.

Open the file "l/ruby/lib/ruby/1.9.1/webrick/config.rb" and locate the line with ":DoNotReverseLookup => nil". Change nil to true.

Enjoy!

Andrew Rukin
  • 959
  • 11
  • 16
0

Is it just as slow using thin?

In your Gemfile..

gem 'thin'

I started using thin to make sure I was matching my production environment and found it to be a bit faster (though, I was never seeing anything as slow as 20seconds..)

Kevin Davis
  • 2,698
  • 1
  • 22
  • 27
0

I had the same problem... anybody find a solution so i switched to Mongrel.

Here is the link with the instructions

Community
  • 1
  • 1
Yeppao
  • 130
  • 2
  • 12