Created
October 4, 2012 15:31
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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:'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've posted some more info of dns related problems and symptoms and updated code to: https://gist.github.com/gabrielf/7746695