Skip to content

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

Description

@szmarczak

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?

Activity

  1. silverwind commented on Jan 18, 2019

    @silverwind
    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?

  2. szmarczak commented on Jan 18, 2019

    @szmarczak
    MemberAuthor

    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)
  3. silverwind commented on Jan 18, 2019

    @silverwind
    Contributor

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

  4. szmarczak commented on Jan 18, 2019

    @szmarczak
    MemberAuthor

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

  5. sam-github commented on Jan 18, 2019

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

  6. szmarczak commented on Jan 18, 2019

    @szmarczak
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions