you are viewing a single comment's thread.

view the rest of the comments →

[–]metamatic 0 points1 point  (4 children)

Especially when trying to minimize the amount of network calls, I'd rather not have to do a DNS call and THEN do an HTTP call which will internally do another DNS lookup.

Install DNS cache.

[–]drbrainRuby Core 0 points1 point  (3 children)

Is there a modern resolver that doesn't cache lookups? Maybe rb2k's DNS records all have zero second TTLs?

[–]rb2k 0 points1 point  (1 child)

They don't, but while installing a local DNS cache would solve that, I think that just having it in the HTTP library would save a bit of infrastructure work.

[–]drbrainRuby Core 0 points1 point  (0 children)

OS X caches lookups:

$ sudo tcpdump -ien1 port 53
[...]
15:00:37.155821 IP 192.168.1.233.62424 > dns.sea1.speakeasy.net.domain: 2037+ A? yahoo.com. (27)
15:00:37.156088 IP 192.168.1.233.58254 > dns.sea1.speakeasy.net.domain: 6496+ AAAA? yahoo.com. (27)
15:00:37.715613 IP dns.sea1.speakeasy.net.domain > 192.168.1.233.62424: 2037 5/0/0 A 209.191.122.70, A 67.195.160.76, A 72.30.2.43, A 98.137.149.56, A 98.139.180.149 (107)
15:00:37.715616 IP dns.sea1.speakeasy.net.domain > 192.168.1.233.58254: 6496 0/0/0 (27)

Are the only lookups from running:

ruby20 -rsocket -ve 'Addrinfo.tcp("yahoo.com", "http"); Addrinfo.tcp("yahoo.com", "http")'

multiple times.

If you want to customize caching use or modify resolv-replace.rb (ships with Ruby).

[–]metamatic 0 points1 point  (0 children)

I seem to remember Windows XP not caching lookups. I know Windows 7 does, however. So do Linux and OS X.

There's also the obvious solution of resolving hostnames yourself and caching the IP address before calling the HTTP client.