lantern icon indicating copy to clipboard operation
lantern copied to clipboard

flashlight - dns lookups use blocking code (at least on Unix)

Open oxtoacart opened this issue 12 years ago • 11 comments

While investigating #1937, I noticed the following cpu profiling output:

       0   0.0%   0.0%     2903  93.3% net.cgoLookupIP
       0   0.0%   0.0%     2903  93.3% net.cgoLookupIPCNAME
       0   0.0%   0.0%     2903  93.3% net.lookupIP

cgoLookupIPCNAME uses getaddrinfo on Unix platforms, which is a blocking call. This might explain why I sometimes see timings for DNS lookups in the 2 second range when running flashlight.

oxtoacart avatar Nov 01 '14 13:11 oxtoacart

Per the release notes for r57, there was a reason for this, namely "This ensures that Go and C programs resolve names the same way and also avoids the OS X application-level firewall".

Since we code-sign flashlight, I think we might be okay to use a custom dns lookup that's non-blocking. Perhaps using miekg/dns.

oxtoacart avatar Nov 01 '14 13:11 oxtoacart

we should cache/tunnel dns entries as mush as possible to avoid host system problem

ed2k avatar Nov 02 '14 16:11 ed2k

Censored clients just do DNS lookups to get to CloudFlare in order to domain front. The DNS lookups for the destination sites are done on the uncensored servers. We want both to be non-blocking.

oxtoacart avatar Nov 02 '14 16:11 oxtoacart

I think the problem is there are multiple DNS resolve call for the same site going out at the same time. even they are non-blocking, they are still redundant. solution should be provide dialer the ip directly, run single dns lookup (for the same site) per time period outside of the dialer. in fact I am not sure why there are so many connections going to the same masquerade, isn't what the connection pool for?

ed2k avatar Nov 04 '14 06:11 ed2k

CloudFlare times out idle connections after about 15 seconds, so in practice stuff doesn't stay in the pool very long.

Regarding caching lookups - yes, we could use that to reduce the number of blocking calls. The problem is that do it right requires considering ttls, to which we only have access if we do the DNS lookup ourselves. In practice, the os already does this, Go just unfortunately uses a blocking api to access it.

oxtoacart avatar Nov 04 '14 10:11 oxtoacart

Is this only the case with Go-only version where Go implements the lookup? I.e. is this still an issue with the latest Natty beta?

myleshorton avatar Nov 12 '14 18:11 myleshorton

Actually, when I wrote this bug, it was on the assumption that the native version was being used. From what I can tell, the pure Go version is unlikely to be an improvement, as it is only intended as a fallback, seems to use locks pretty heavily and has warnings about needing to be better optimized. I think we might see performance improvements now that the cross-compilation includes the native version, but I'd like to keep this open to investigate in more detail once there's time.

oxtoacart avatar Nov 12 '14 18:11 oxtoacart

Cool; do you envision doing investigation in more the 3-month (i.e., short-term) or 6-month (medium-term) timeframe?

scouttle avatar Nov 12 '14 19:11 scouttle

More like 3 months, though it might eventually become 6 months :)

oxtoacart avatar Nov 12 '14 19:11 oxtoacart

The flashlight client doesn't do any DNS lookups anymore (right?), so at least we may be able to ignore any considerations that don't apply to linux (e.g. the OS X application-level firewall).

aranhoide avatar Nov 19 '14 17:11 aranhoide

It doesn't do dns lookups for masquerades, but still does for s3 config lookups (except when running as a client).

oxtoacart avatar Nov 19 '14 17:11 oxtoacart