Skip to content
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 lookup is not cached the way I understand #67

Open
menocomp opened this issue Aug 21, 2022 · 1 comment
Open

dns lookup is not cached the way I understand #67

menocomp opened this issue Aug 21, 2022 · 1 comment

Comments

@menocomp
Copy link

Hello there,

I could be missing something here.

I am trying to reduce the calls that go to dns.lookup in order to reduce the C++ libuv threads allocation so I am using this library.

How I am testing that, by running this code:

const nodeDnsLookup = dns.lookup;
let dnsLookupCounter = 0;
dns.lookup = (...args) => {
  console.log(`I am calling the native node dns lookup ${JSON.stringify(args)}, number ${dnsLookupCounter}`);
  dnsLookupCounter++;
  return nodeDnsLookup(...args);
};

so, without installing this library I can see a lot of dns lookups.

Now after I installed this library with its global http(s) agent as follows:

import CacheableLookup from 'cacheable-lookup';
const cacheable = new CacheableLookup();

cacheable.install(http.globalAgent);
cacheable.install(https.globalAgent);

I was expecting the number of dns lookups would go down and cache hits to happen, but it did not!
I see from the logs that the same hostname with the same family are still calling the native dns.lookup and not served from a cache.

@szmarczak
Copy link
Owner

Can you confirm if manually using https://nodejs.org/api/dns.html#dnsresolve4hostname-options-callback returns data?

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

No branches or pull requests

2 participants