Skip to content

perf(quic): cache DNS resolutions for a short TTL - #208

Open
thexeos wants to merge 1 commit into
cloudflare:draft-ietf-moq-transport-14from
thexeos:perf/dns-resolution-cache-draft-14
Open

perf(quic): cache DNS resolutions for a short TTL#208
thexeos wants to merge 1 commit into
cloudflare:draft-ietf-moq-transport-14from
thexeos:perf/dns-resolution-cache-draft-14

Conversation

@thexeos

@thexeos thexeos commented Aug 13, 2026

Copy link
Copy Markdown

Backport of #203 to draft-14

quic::Client::connect() resolves the peer hostname on every attempt, so each connection pays a resolver round trip even though a client typically connects to the same small set of hosts over and over. This adds a short-lived cache in front of resolve_dns(), keyed on host, port and the local socket's address family (resolution filters answers by family, so it belongs in the key). Entries expire after DEFAULT_DNS_CACHE_TTL (30s) and the TTL is adjustable per client via with_dns_cache_ttl(), with zero disabling the cache; failed lookups are never cached, and literal addresses and the explicit SocketAddr argument to connect() bypass it entirely. Implemented with HashMap + Mutex from std (no new dependency) and covered by unit tests that exercise expiry and keying without touching the network.

Client::connect() resolved the peer hostname on every attempt, so every
connection paid a resolver round trip even though the same small set of
hosts is connected to repeatedly, on a path where the latency is visible.

Put a TTL cache in front of resolve_dns(), keyed on host, port and the
local socket's address family - resolution filters answers by family, so
the family is part of what determines the result. Entries expire after
DEFAULT_DNS_CACHE_TTL (30s), adjustable per client with
with_dns_cache_ttl(); a zero TTL disables caching. Failed lookups are
never cached, literal addresses and the explicit SocketAddr argument to
connect() bypass the cache entirely, and expired entries are swept on
insert so the map stays bounded. Uses only std (HashMap + Mutex), so no
new dependency.
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

Successfully merging this pull request may close these issues.

1 participant