Using resolve-replace to fix blocking Net::HTTP requests

posted: November 10th, 2007 · by: Sven

in: Programming ·  7 comments »

It took me a while to find relevant some info on this, so I thought I’d blog about it for others to find this more quickly with the keywords that I thought were a good starting point at first.

I’ve been running an outdated version of Mongrel (1.0.1 as of Jan 07) when I switched to Leopard. Everything continued to work fine except that I noticed (a while later) some the Ajax calls that call Net::HTTP to load some info from a webservice or external website would take very long or even would timeout.

I’m not really sure what’s going on there, but Apple seems to have changed a lot in how Mac OS X handles DNS lookups in Leopard … and these seem to block when they didn’t in Tiger.

After some googling I found that requiring the Ruby Standard Library piece ‘resolv-replace’ would fix this issue. Just put this line somewhere in your app where it get’s loaded at startup:

require 'resolv-replace'

I noticed only later on that my Mongrel is outdated, too, and updated it. (There were three consecutive releases around the end of Okt 07.)

This also seems to fix the same issue. With different results, though. With Mongrel 1.1 things are back to a usable speed and requests aren’t blocked any more. But it’s still ~22 times faster to use resolv-replace, too:

Requests in my locale Mephisto setup without resolv-replace:

0.061855 milliseconds on average

With resolve-replace:

0.002755 milliseconds on average

To “benchmark” this I used:

start_time = Time.now
Net::HTTP.get_response(URI.parse('http://localhost/something.html'))
puts Time.now - start_time

PS: Now that I started writing this blog post I googled for different keywords and it turns out that no other than Joshua Harvey blogged about the very same issue in Dec 2005. Funny, I could just have asked him about it. The world is small, sometimes. :)

Leave a comment

7 Comments

  1. ehsanul said February 15th, 2009 at 02:22 AM  

    I know this is late as hell, but thanks! This is going to help me.

  2. jack said January 23rd, 2011 at 11:12 AM  

    Hey, that’s cool. Would be awesome to have this ready for VIM in some prepackaged form. I’m not so much into VIM lately, as you know cheap vps

  3. Chung2 said February 24th, 2011 at 10:46 AM  

    How able-bodied does url browse play with SharePoint! pass4sure 70-552 Are there any issues that may be encountered by installing it on a server after testing it with any custom applications first! pass4sure 70-561 Is there a account of what url browse checks for out of the box so we can try to amount out in beforehand if there may be issues with our custom apps! pass4sure 70-562 Can i use Request Filtering affection in Server 2008 R2 IIS 7.5 instead of URL Scan? pass4sure 70-634 The aftereffect of abstinent the concern cord with that is an IIS 404 absurdity unless that is redirected.

  4. chat said March 31st, 2011 at 07:01 PM  

    Here is a fix for the resolve-replace issue:

    Dependencies.loadoncepaths -= Dependencies.loadoncepaths.select{|path| \ path =~ %r(^#{File.dirname(FILE)}) }

  5. Okey oyunu said May 12th, 2011 at 03:48 PM  

    Tüm dünya artik okey oyunu oynuyor. Yillardir bir çok oyun programi olmasina ragmen, içlerinden en güzeli olarak nitelendirebilecegimiz tek bir site göze çarpmaktadir. Diger tüm okey oyunu programlarinin aksine ücretsiz olmasi ve 3 boyutlu olarak hizmet vermesi mükemmel bir gelismedir. Sizlerde www.okey-oyunu.com adresinden bu essiz okey oyununu indirebilirsiniz. Kullanimi çok basit ve Türkçe dil seçenegi ile kolaylikla oyuna baslayabilirsiniz. Ister kendi ülkenizden, isterseniz dünyanin tüm farkli bölgelerinden dilediginiz oyun odalarini seçerek, oyuna hemen baslayabilirsiniz. Okey oyunu oynamak için artik arkadas bile aramaniza gerek kalmadan, bilgisayarinizdan 100 binlerce üye ile online olarak okey oyununu oynamanin zevkine varabilirsiniz.

  6. porno said May 22nd, 2011 at 01:31 PM  

    I do agree with all of the ideas you have presented in your post. They’re really convincing and will definitely work. Still, the posts are too short for newbies. Could you please extend them a bit from next time? Thanks for the post.

  7. porno said May 22nd, 2011 at 02:07 PM  

    good comment. thanks you friends.

    I’ve surfed the net more than three hours today, however, I haven’t found such useful information. Thanks a lot, it is really useful to me

Sorry, comments are closed for this article.

artweb design
Sven Fuchs
Grünberger Str. 65
10245 Berlin, Germany


http://www.artweb-design.de

Fon +49 (30) 47 98 69 96
Fax +49 (30) 47 98 69 97