Why is WEBrick processing my request so slowly on OSX?
I created a basic demo application in Rails 3.2.2 using the new rails demo. Then I added a controller with a single method that renders the view. It takes an average of 20+ seconds to render the page on refresh. This obviously makes development impossible, so I'm trying to figure out why and how I can fix this.
I have to mention that I'm on a 2011 Macbook Air with 4GB of RAM and an SSD, so I don't think my hardware has anything to do with this issue.
Running OSX Lion, Rails 3.2.2, and Ruby 1.9.3. Run locally via WEBrick
Update
The only changes I made was to run rails generator Say hello goodbye
.
Then I modified 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'
Launched the server by typing rails server
Update 2
I noticed this oddity in the terminal window. it takes 8 seconds from the start of GET to GET in 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 traced the issue back to WEBrick. I installed and used thin instead and my calls are very fast as expected. It would be nice to find out what could be the problem if the WEBrick problem is a symptom of a more serious problem.
source to share
Not really an answer, but might help highlight the problem:
try another server like "thin" or "pow" http://pow.cx/ (btw: pow is completely rocky !, and consider installing a powder
gem that gives good command line tools.) Pow is very easy to install.
Also, check your memory usage with the Activity Monitor app - 4GB sounds like a lot, but it can drain quickly. But I am running the same environment and have no problem.
I have no idea that this is an asset compilation issue - with a squeaky-clean Rails application there doesn't need to be much compilation. But timings are a curse - perhaps check which process is chewing on the CPU (or perhaps the disk) while it waits. You can eliminate the asset pipeline by setting config.assets.enabled = false
to application.rb
.
One more thing to check: you are up to the latest ruby ββ1.9.3 - I've seen strange things on 1.9.3-p0 and am now using 1.9.3-p125 and all is well.
And one more thing to check: use curl
or wget
from the command line to separately request a page from the assets themselves.
Oh, and are you using Time Machine? My car gets very pokey sometimes when it's running. There shouldn't be the same problem with an SSD, but ... who knows.
source to share
+1 for asset precompilation problem
I will try to answer how you can fix this (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 might be a good approach (for me it sped up pages showing about 30-40% versus webrick)
hope this helped
source to share
I had a similar problem, but I'm not sure if the solution will apply to you too. My problem was mostly related to unnecessary reverse lookups. Take a look at this question as it might help: Webrick is very slow to respond. How to speed it up?
source to share
I theorize that there is some kind of compilation or copy of the assets every time.
I would try changing the compilation of assets as a test -
In Rails 3.1, the resource pipeline is enabled by default. It can be disabled in config / application.rb by placing this line in your application class definition: config.assets.enabled = false
I would be very interested to know if you have a large (or large number) of images or other media resources.
source to share
WEBrick performs reverse DNS lookup when connecting default IP addresses. In other words, it tries to determine if your IP address is associated with a domain name. This is optional and takes too long, so you can disable it.
Open the file "l / ruby ββ/ lib / ruby ββ/1.9.1/webrick/config.rb" and find the line with :: DoNotReverseLookup => nil. Change nil to true.
Enjoy!
source to share