Skip to content

proposal: net: cache DNS responses #24796

Closed
@iangudger

Description

@iangudger

The new DNS client is significantly more efficient than the old one, but it hasn't changed overall performance much as the most expensive part by far is the network. If a user dials the same domain repeatedly, we shouldn't need to ask the DNS server each time in most situations.

I propose that we cache the parsed result along with the expiration time of the minimum TTL from the RRs used to create said result. This allows us to keep the benefits of incremental parsing and should minimize the performance impact of caching by minimizing what needs to be copied into and out of the cache. The caching logic would go at the call sites of net.(*Resolver).loopup.

We may want/need to rotate the order of the responses returned from the cache.

The simplest eviction strategy is to only evict expired results from the cache. If we want to limit maximum size, we could do LRU + expired.

https://www.ietf.org/rfc/rfc1034.txt
https://www.ietf.org/rfc/rfc1035.txt
https://tools.ietf.org/html/rfc2181#section-7 (SOA TTLs)
https://tools.ietf.org/html/rfc2181#section-8
https://tools.ietf.org/html/rfc1123#section-6.1.2.1
https://00f.net/2011/11/17/how-long-does-a-dns-ttl-last/ (article on the behavior of various caching DNS servers)

/cc @mikioh @bradfitz @mdempsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions