Repository navigation
Specify servers for dns.lookup(...) #25560
Description
Activity
Is it somehow possible to select the servers for dns.lookup?
Regular
dnsmethods use the servers set bydns.setServersbefore the query.The performance of Resolver.resolve4/Resolver.resolve6 is very poor
Can't say I noticed this. Do you have an minimal benchmark?
Regular dns methods use the servers set by dns.setServers before the query.
Okay, except this is global. All things that use the
dnsmodule will be affected.Can't say I noticed this. Do you have an minimal benchmark?
Yup: https://github.com/szmarczak/cacheable-lookup/blob/master/benchmark.js
dns#resolve4 x 27.03 ops/sec ±41.64% (246 runs sampled) dns#lookup x 5,994 ops/sec ±0.26% (285 runs sampled)
this is global
Yeah,
dns.Resolveris your only option then.Regarding your benchmark, you have to keep in mind that all
resolvevariants contact your DNS server whilelookupdoes not involve DNS or the network (on Linux, it's just a glibc call), solookupwill be faster by a magnitute in all cases. I'd be surpised if there were any major performance difference betweendnsanddns.Resolvermethods.And to answer your question on servers/TTL for
lookup: It is not possible because underlying calls like getaddrinfo have no concept of servers or TTL (caching is done on OS level instead).And to answer your question on servers/TTL for lookup: It is not possible because underlying calls like getaddrinfo have no concept of servers or TTL (caching is done on OS level instead).
Very well explained, I understand now :)
you have to keep in mind that all resolve variants contact your DNS server while lookup does not involve DNS or the network (on Linux, it's just a glibc call)
Sodns.setServers()won't affectdns.lookup()?no concept of servers
Thank you for your help :)
@szmarczak you crossed out your question about setServers() and dns.lookup()?
The answer is "no", for posterity. Its implied by https://nodejs.org/api/dns.html#dns_dns_lookup to someone who knows how the system resolvers work and are configured, but your question makes me think it should be stated more explicitly.
https://nodejs.org/api/dns.html#dns_dns_setservers_servers use the word "resolution" in its text, but maybe that's not explicit enough, and a note to the effect that it does not effect dns.lookup() should be added.
you crossed out your question about setServers() and dns.lookup()?
@silverwind has given the answer already:
It is not possible because underlying calls like getaddrinfo have no concept of servers or TTL
your question makes me think it should be stated more explicitly.
Indeed.
The performance of
Resolver.resolve4/Resolver.resolve6is very poor (~15 ops/sec).As I see it, it does the same as
dns.lookupbut you can select custom DNS servers as well as you can also get the TTL.The performance of
dns.lookupis ~6000 ops/sec. Is it somehow possible to select the servers fordns.lookup?