-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add in-memory cache for DNS #6073
Merged
Merged
Conversation
This file contains 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
link2xt
force-pushed
the
link2xt/dns-in-memory-cache
branch
3 times, most recently
from
October 20, 2024 05:58
2acaa2d
to
6485951
Compare
link2xt
force-pushed
the
link2xt/dns-in-memory-cache
branch
from
October 20, 2024 15:38
6485951
to
58cab7b
Compare
Hocuri
reviewed
Oct 20, 2024
link2xt
force-pushed
the
link2xt/dns-in-memory-cache
branch
from
October 20, 2024 18:14
58cab7b
to
ad20db5
Compare
link2xt
force-pushed
the
link2xt/dns-in-memory-cache
branch
from
October 20, 2024 18:32
ad20db5
to
2c317ce
Compare
iequidoo
reviewed
Oct 20, 2024
Hocuri
approved these changes
Oct 20, 2024
Hocuri
reviewed
Oct 20, 2024
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.
This adds "stale-while-revalidate" in-memory cache for DNS. Instead of calling
tokio::net::lookup_host
we use previous result oftokio::net::lookup_host
immediately and spawn revalidation task in the background. This way all lookups after the first successful return immediately.Most of the time results returned by resolvers are the same anyway, but with this cache we avoid waiting 60 second timeout if DNS request is lost. Common reason result may be different is round-robin DNS load balancing and switching from IPv4 to IPv6 network. For round-robin DNS we don't break load balancing but simply use a different result, and for IPv6 we anyway likely have a result in persistent cache and can use IPv4 otherwise.
Especially frequest should be the case when you send a message over SMTP and SMTP connection is stale (older than 60 s), so we open a new one. With this change new connection will be set up faster as you don't need to wait for DNS resolution, so message will be sent faster.