Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify servers for dns.lookup(...) #25560

Closed
szmarczak opened this issue Jan 18, 2019 · 6 comments
Closed

Specify servers for dns.lookup(...) #25560

szmarczak opened this issue Jan 18, 2019 · 6 comments

Comments

@szmarczak
Copy link
Member

The performance of Resolver.resolve4/Resolver.resolve6 is very poor (~15 ops/sec).

As I see it, it does the same as dns.lookup but you can select custom DNS servers as well as you can also get the TTL.

The performance of dns.lookup is ~6000 ops/sec. Is it somehow possible to select the servers for dns.lookup?

@silverwind
Copy link
Contributor

Is it somehow possible to select the servers for dns.lookup?

Regular dns methods use the servers set by dns.setServers before the query.

The performance of Resolver.resolve4/Resolver.resolve6 is very poor

Can't say I noticed this. Do you have an minimal benchmark?

@szmarczak
Copy link
Member Author

szmarczak commented Jan 18, 2019

Regular dns methods use the servers set by dns.setServers before the query.

Okay, except this is global. All things that use the dns module 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)

@silverwind
Copy link
Contributor

silverwind commented Jan 18, 2019

this is global

Yeah, dns.Resolver is your only option then.

Regarding your benchmark, 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), so lookup will be faster by a magnitute in all cases. I'd be surpised if there were any major performance difference between dns and dns.Resolver methods.

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).

@szmarczak
Copy link
Member Author

szmarczak commented Jan 18, 2019

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)

So dns.setServers() won't affect dns.lookup()?

no concept of servers

Thank you for your help :)

@sam-github
Copy link
Contributor

@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.

@szmarczak
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants