flashlight - dns lookups use blocking code (at least on Unix)
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.
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.
we should cache/tunnel dns entries as mush as possible to avoid host system problem
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.
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?
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.
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?
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.
Cool; do you envision doing investigation in more the 3-month (i.e., short-term) or 6-month (medium-term) timeframe?
More like 3 months, though it might eventually become 6 months :)
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).
It doesn't do dns lookups for masquerades, but still does for s3 config lookups (except when running as a client).