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


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'

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 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 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 at 2012-03-10 22:49:24 -0700
Served asset /say.css - 200 OK (0ms)



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

7 replies

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.



+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


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



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?



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.



Is it really just as slow using thin?

In your Gemfile ..

gem 'thin'


I started using thin to make sure I matched my production environment and found it to be slightly faster (although I've never seen anything as slow as 20 seconds).



I had the same problem ... somebody found a solution, so I switched to Mongrel.

Here is a link with instructions



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.




All Articles