Mike Perham

On Ruby, software and the Internet

Asynchronous DNS Resolution

February 10th, 2010 · 3 Comments

Ruby has a serious scalability problem most Rubyists are unaware of. When you lookup the IP address for a hostname, the entire Ruby process blocks by default. If you have a slow DNS server, your process can grind to a halt waiting for hostname resolution. Ruby comes standard with a fix, resolv-replace, which provides a DNS resolver that does not block the entire process. It does however block the Thread, like any other instance of blocking I/O.

So I wrote an EventMachine-aware DNS resolver that ensures that your asynchronous operations don’t block while performing DNS resolution. Take a look at em-resolv-replace and give it a whirl.

Tags: Ruby

3 responses so far ↓

  • 1 Julien // Feb 11, 2010 at 2:09 am

    Awesome… Our @astro wrote em-dns a while ago… How does it compare?

  • 2 Nestor Wheelock // Feb 11, 2010 at 8:39 pm

    Not much of a ruby guy but stumbled on your page and took a look at your em-resolv-replace and checked out the resolv.rb library. You might also check out the c-ares lib.

    “C-ares is an asynchronous resolver library. It is intended for applications which need to perform DNS queries without blocking, or need to perform multiple DNS queries in parallel. The primary examples of such applications are servers which communicate with multiple clients and programs with graphical user interfaces.”

    It’s an expansion/fork of the ares lib…the ares author wasn’t prepared to accept the changes they deemed necessary to meet the author’s requirements. Some of which are: not blocking sockets, being thread friendly, portable, and fast.

    Read more about why here:

    http://c-ares.haxx.se/why.html

  • 3 mperham // Feb 11, 2010 at 10:52 pm

    Julien, my gem is based on @astro’s em-dns. He’s credited in the readme.

Leave a Comment