Monday, October 10, 2011

Introducing Mono.Dns

The internal implementation of System.Net.Dns in Mono ends up calling getaddrinfo () or some other similar function in libc. This is perfectly fine for most applications. However, sophisticated applications that perform more than just a few DNS queries, like crawlers, aggregators, and log processors, are taking a big performance hit when running under Mono. One of the issues is that the libc implementation is not optimized to be used from multiple threads. Barring an external library dependency, there is not much that can be done to address that problem. Another issue is that the implementation of the asynchronous methods in System.Net.Dns are based on asynchronous delegates invoking the synchronous version of the methods. In other words, calling, for instance, Dns.BeginGetHostAddresses () will use a threadpool thread to block on the call to Dns.GetHostAddresses (). Mono.Dns is here to address these problems and more.

The Mono.Dns assembly provides a set of classes that can help you implement a DNS client or server. There is also an implementation of a simple asynchronous DNS resolver with an API inspired by the System.Net.Socket.Socket.*Async() set of methods. The source code is available in the Mono.Dns GitHub repository. There is an example of use in test/resolver.cs.

As an example of the performance advantage, grab the plainolddns.cs file, compile it, and download this file. Make sure you pull the latest Mono from the master branch and run the program like this:

$ mono plainolddns.exe $(cat google-domains.txt)
...A BUNCH OF NAMES and IP ADDRESSES
...
00:00:18.4342605

Read more: Sin ley
QR: Oct-09.html

Posted via email from Jasper-Net