Skip to content

Instantly share code, notes, and snippets.

@robertlmullen74
Created October 4, 2012 15:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save robertlmullen74/3834431 to your computer and use it in GitHub Desktop.
Save robertlmullen74/3834431 to your computer and use it in GitHub Desktop.
Node.js tester of dns lookup vs ip using the dns module
// This gist is helpful in determining if the dns resolution is the bottleneck when making
// outbound http request
var dns, http, util;
util = require('util');
dns = require('dns');
function outputMs()
{
var d = new Date();
var n = d.getUTCMilliseconds();
return n;
}
// enter your ip and dns that you are comparing below
var iphost = '<enter IP here>';
var host = '<enter dns name here>';
util.log("start dns lookup ms:" + outputMs());
var startTime = outputMs();
dns.lookup(host, 4, function(err, address, family) {
var totalTime = startTime - outputMs();
return util.log("dns lookup took " + totalTime + 'ms:');
});
dns.resolve(host, function(err, address, family) {
var totalTime = startTime - outputMs();
return util.log("dns resolve took " + totalTime + 'ms:');
});
util.log("start lookup for ip ms:" + outputMs());
var startTime = outputMs();
dns.lookup(iphost, 4, function(err, address, family) {
var totalTime = startTime - outputMs();
return util.log("dns ip lookup took " + totalTime + 'ms:');
});
dns.resolve(iphost, function(err, address, family) {
var totalTime = startTime - outputMs();
return util.log("dns ip resolve took " + totalTime + 'ms:');
});
@gabrielf
Copy link

gabrielf commented Dec 2, 2013

I've posted some more info of dns related problems and symptoms and updated code to: https://gist.github.com/gabrielf/7746695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment