[Python-Dev] _socket efficiencies ideas
Guido van Rossum
guido@python.org
Wed, 09 Apr 2003 14:45:49 -0400
> Sean Reifschneider wrote:
>
> > My first thought is that there should be a local DNS cache on the
> > machine that is running these apps. My second thought is that Python
> > could benefit from caching some lookup information...
[MvL]
> I disagree. Python should expose the resolver library, and leave
> caching to it; many such libraries do caching already, in some form.
Right.
> The issue is different: In some cases the application just *knows*
> that an address is numeric, and that DNS lookup will fail.
In fact, I've often written code that passes a numeric address, and
I've always assumed that in that case the code would take a shortcut
because there's nothing to look up (only to parse).
> In these cases, lookup should be avoided - whether by explicit
> request from the application or by Python implicitly just knowing is
> a different issue.
>
> It turns out that Python doesn't need to 100% detect numeric
> addresses, as long as it would not classify addresses as numeric
> which aren't. Perhaps it is even possible to leave the "is numeric"
> test to the implementation of getaddrinfo, i.e. calling it twice
> (try numeric first, then try resolving the name)?
Perhaps, as long as we can safely ignore the first error. This would
probably be a little slower, but probably not slow enoug to matter,
and it sounds like a very general solution.
--Guido van Rossum (home page: http://www.python.org/~guido/)