Skip to content

Add DNS Cache that respects TTL of resolved DNS records #28

@lidel

Description

@lidel

Problem

When DNS over HTTPS resolver is set up, every query produces HTTP request.

To illustrate, when using https://resolver.cloudflare-eth.com/dns-query for crypto TLDs, this adds around 1 second to EVERY resolution event (only the very first one should be that slow):

$ t ipfs name resolve /ipns/brave.crypto
/ipfs/QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka
  0.25s user 0.03s system 21% cpu 1.274 total

$ t ipfs name resolve /ipns/brave.crypto                                                                                                                                                    /ipfs/QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka
  0.21s user 0.02s system 20% cpu 1.100 total

$ t ipfs name resolve /ipns/brave.crypto                                                                                                                                                   
/ipfs/QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka
  0.23s user 0.02s system 23% cpu 1.058 total

To illustrate, using non-DoH name leverages OS-level resolver as a cache, and only first lookup is expensive:

$ t ipfs name resolve /ipns/en.wikipedia-on-ipfs.org                                                                                                                                        
/ipfs/bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze
  0.23s user 0.05s system 80% cpu 0.343 total

$ t ipfs name resolve /ipns/en.wikipedia-on-ipfs.org                                                                                                                                        /ipfs/bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze
  0.04s user 0.01s system 173% cpu 0.029 total

$ t ipfs name resolve /ipns/en.wikipedia-on-ipfs.org                                                                                                                                        /ipfs/bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze
  0.03s user 0.02s system 160% cpu 0.032 total

Solution

The problem is not limited to DoH – there is no point in hitting OS-level default resolver if we could use cached record.
We need to add a global DNS Cache to resolve.go that makes sure we don't do redundant lookups until TTL from resolved record expires.

cc @aschmahmann @vyzo what would be the least painful way to solve this globally?

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