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..
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
powdergem 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 = falsein yourapplication.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
curlorwgetfrom 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.