perf(quic): cache DNS resolutions for a short TTL - #203
Open
thexeos wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofresolve_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 afterDEFAULT_DNS_CACHE_TTL(30s) and the TTL is adjustable per client viawith_dns_cache_ttl(), with zero disabling the cache; failed lookups are never cached, and literal addresses and the explicitSocketAddrargument toconnect()bypass it entirely. Implemented withHashMap+Mutexfrom std (no new dependency) and covered by unit tests that exercise expiry and keying without touching the network.