Page 1 of 1

DNS Testing

Posted: Sat Jun 21, 2008 3:28 pm
by dave
I have finally finished my PHP DNS API and integrated it into FreeNATS along with some simple DNS tests. This is now available in the 0.04.16a release now up for alpha testing. The functionality is not yet documented so I thought I'd post a few details here for testers/early adopters.

Simple DNS Queries
Takes a hostname or IP address and (depdendent on the type it determines the input to be) does a gethostbyname() or gethostbyaddr(). Will return a negative result and fail simple evaluation if the lookup fails else returns elapsed time in seconds.

Complex DNS Queries
These use my PHP DNS query API classes and perform a socket level transaction with the nameserver specified to ask the question given. This system (unlike ICMP/Ping) does not use raw sockets (opens with fsockopen()) so usually requires no special privs. To aid diagnostics there is also now a DNS Console link on the admin page which includes a wrapper for the DNS client.

Complex queries connect to the namesever given (or the node's hostname if unspecified) using the specified port (or default 53) and protocol (TCP or UDP). Types of query available are A, PTR, MX, NS and SOA.

The test will return a negative result (and fail simple evaluation) if the query totally fails or returns no answers otherwise will return a time in seconds taken (and pass simple evaluation).

This will mean the test passing if any record matching the query is returned so for example an A query may merely return a CNAME pointer but this is still a valid answer and so the test will pass (obviously other fields for the host such as TXT and MX do not get returned for an A type of query though).

Timing Complex DNS Queries
DNS is a fast protocol at heart. It is a very tight old-school "every bit matters" sort of affair and about as far away from developer-friendly XML as possible. But... although I could write an amazingly fast client in C doing it in a higher-level language like PHP involves a large overhead of packing binary data into packets and then unpacking data in obscure forms from binary back into something more usable (at least if you are as mathematically incompetent as me).

The actual sending of the query and waiting for the response is usually the shortest part of the operation (especially if using UDP to a nameserver on localhost) compared to the initialisation, packing, unpacking, parsing and evaluating the DNS API does. In my defence I never developed it purely for speed more for flexibility for the developer (if you want a speedy lookup use the environment's inbuilt lookup after all).

Unfortunately in developing the DNS test as a total standalone API I neglected to consider that now FreeNATS is only capable of timing the entire process of the query including all the processing overhead (unlike the other tests which do all their initilisation, start the timer, perform the test, stop the timer and then process the results so the time given is as true as possible how long the actual operation took rather than being held back by my flaky code).

Now having said all this I must say the times do seem pretty quick and the overhead (although perhaps significant when the UDP query to a local nameserver takes <1ms) may well be insignificant in the long run.

If it does become a problem then I plan to implement a timer facility within the DNS API itself which will record how long just the query took to come back from the server.