-
-
Notifications
You must be signed in to change notification settings - Fork 941
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
DNS cache #661
Comments
Node.js has ability to get the TTL of DNS lookups: nodejs/node#9296 So we could potentially implement a simple automatic cache based on that. Some prior art (which all seems to require setting TTL manually): |
@sindresorhus I would like to work on that |
I think the ideal implementation would be an automatic TTL cache by simply respecting the TTL of the DNS record itself. If the upstream DNS server(s) are respecting TTL to spec, they will be caching for the same TTL meaning a value lower than set on the DNS record is unnecessary. As for a size limit, I don't think it's necessary. Absolute worst case, a domain (63 characters) and IPv6 address (128 bit) pair are represented in 79 bytes. That means you can store 12,658 cached DNS entries per megabyte of memory. In practice, you'd get 25,000+ since domains are shorter. For long running processes, we could implement an asynchronous tick (e.g. If we implement it similar to request caching, the user can bring their own cache if they need to manage it more closely. For instance, passing in a custom instance of We should however offer an option to disable it. This leaves us with two modes:
Just my $0.02. |
btw can anyone assign this issue to me, because I'm already working on it (if it's necessary) |
ok, so the cache is almost ready but I don't know what to do with resolving |
Wouldn't it make sense to simply accept a |
@pietermees default About
For more info please refer to this doc. And there is definitely no point to add another dependency because it's not so much code to do. |
@morozRed sorry, I should have been clearer. I meant to ask why DNS caching should be part of The reason why I ask is that Node APIs already allow overriding DNS lookups on TCP/HTTP/HTTPS/H2 connects by providing a custom My main point is that adding a |
@pietermees oh ok, well the idea was to make automatic pre-initialized DNS cache, but still, you already able to do this: await got('google.com', { lookup: CUSTOM_DNS_CACHE.lookup }); |
Having played around with some of the DNS cache implementations that are around, I think you'll find that you can't easily provide a default DNS cache that is fully transparant (i.e. handles DNS exactly the same way as the system would). As you've indicated you have to use the With that in mind, I don't think it's possible to provide an implementation that's enabled by default and does not change semantics for all Hence my suggestion to use the
|
ok so @sindresorhus @brandon93s what do you guys think about it? Maybe I can update the docs here at least? |
What should we do when the DNS server offers us multiple IP addresses? Should we cache them? |
@szmarczak you can cache all the addresses and then use round-robin strategy. But I'm not sure now if we do need to implement custom cache if you can simply pass package or custom lookup function to got. |
Well, there isn't one which will set TTL automatically... We need to create it :) |
@szmarczak this package supports provided DNS TTL. I've been working on cache for got but then I got stuck because of this discussion. |
Well, it sounds good... but it isn't. It's way too bloated. Is there any way to manage the database? I'll try to make a prototype now :) |
To be fair, that's mostly because it pulls in |
@sindresorhus Any ideas on how to implement |
|
I do understand that mabe it's not the purpose of this lib (feel free to close in case).
But would be useful adding a dns cache layer.
It's one of the common problem nowadays with huge number of requests. It doesn't cache dns lookups or anything. Maybe it's worth just mentioning this in Readme.
What's the cleanest way to deal with it?
The text was updated successfully, but these errors were encountered: