I had a vaguely similar problem that manifested itself when accessing a WEBrick server via a VPN. Requests would take a long time, most of it with nothing happening on the wire.
Since neither mongrel nor thin gems worked with Ruby1.9 on Windows and there was no way I was getting myself embroiled in compiling stuff from source, I needed to stick with WEBrick.
The fix was to set the config parameter DoNotReverseLookup to true, when creating the WEBrick server:
server = HTTPServer.new {:DoNotReverseLookup => true, ...}
Had the same problem. For me, this post held the solution. If you are on Ubuntu, stop (or uninstall) the avahi-daemon. service avahi-daemon stop stops the daemon.
Was trying to do this with webrick on 1.8.7 and couldn't find the config to change. However, a cheat you can use is to add to the hosts file of the server which is running webrick the ip address it is trying to reverse lookup..
Switch to a concurrent web backend like Unicorn or Puma on JRuby, which allows the dyno to manage its own request queue and avoid blocking on long requests.
In my probably rare situation, it worked after I flushed my iptables, this didn't have any side effects because I didn't have any custom rules (just the default Ubuntu allow all):
I experienced 10 seconds delays frequently with Sinatra. This snippet solved it for me.
Add this near the top of your app.rb file
class Rack::Handler::WEBrick
class << self
alias_method :run_original, :run
end
def self.run(app, options={})
options[:DoNotReverseLookup] = true
run_original(app, options)
end
end
This is a very late answer but I spent a good part of the day debugging this very issue with Rails running on Vagrant. Changing the reverse DNS lookup didn't actually improve request times at all. A combination of two things took my page load from ~20 seconds to ~3 seconds in development mode:
Replace WEBrick with mongrel. I had to use the prerelease version or it wouldn't install:
sudo gem install mongrel --pre
Then add it to my Gemfile for dev:
group :test, :development do
gem 'mongrel'
end
Started my server like this then:
rails server mongrel -e development
That cut a few seconds off, 5 or 6 seconds, but it was still terribly slow. This was the icing on the cake - add this as well to the Gemfile:
group :development do
gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git'
end
This is an old question and answer thread that helped me solve the :DoNotReverseLookup issue on a local development virtual machine and wanted to add additional info. This web page explains the regression error in Ruby core that lead to this issue appearing for some; emphasis is mine; the long an short of all of this is there is a GitHub pull request for a Ruby core fix to this and hopefully it will be approved and merged in a soon-ish release of Ruby:
After a few hours of troubleshooting, it turned out that it was!
Apparently, somewhere along the evolution of Ruby's standard lib from
1.8.6 to 2.0.0, WEBrick acquired a new configuration option :DoNotReverseLookup that is set to nil by default. Then, deep in the
guts of WEBrick's request processing code, it sets the
do_not_reverse_lookup flag on the incoming connection socket instance
to the value of config[:DoNotReverseLookup]. Since this value is nil,
which is falsy, the effect is the same as setting it to false,
overriding the global Socket.do_not_reverse_lookup flag. So, unless
you have :DoNotReverseLookup => true in your WEBrick config, reverse
DNS lookup will always happen for each new connection, potentially
causing serious latency.
Sharing here if anyone stumbles over this well regarded question/answer thread and are interested in the progress in solving this issue in Ruby core. Hopefully this pull will be merged or the underlying issue be dealt with in some way in the next release of Ruby; maybe 2.1.6?