gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

anntzer.lee at gmail.com anntzer.lee at gmail.com
Sun Sep 1 00:51:47 EDT 2013


It is the call to gethostbyname_ex that is very slow.  The call to gethostname is quick (and returns the same string as /usr/bin/hostname).

On Saturday, August 31, 2013 6:01:00 PM UTC-7, Roy Smith wrote:
> In article <b9f77b6f-3a65-407a-aff5-5677be2ba228 at googlegroups.com>,
> 
>  anntzer.lee at gmail.com wrote:
> 
> 
> 
> > Hi,
> 
> > 
> 
> > At startup, IPython (qtconsole) calls 
> 
> > "socket.gethostbyname_ex(socket.gethostname())[2]" to find a list of IP 
> 
> > addresses that point to the machine. On a Linux server that I manage this 
> 
> > call is extremely slow (>20s)... which I have trouble understanding as "ip 
> 
> > addr show" seems to give the same information nearly instantaneously. Is 
> 
> > there anything I can do to make this faster? Can this be a network 
> 
> > configuration issue (I am behind a router)?
> 
> 
> 
> It's almost certainly some sort of configuration issue which is causing 
> 
> some DNS query to timeout.  The first step, is to figure out which part 
> 
> is taking so long.  Open up a python shell and run:
> 
> 
> 
> >>> name = socket.gethostname()
> 
> 
> 
> see how long that takes and what it returns.  Then, assuming it returns 
> 
> a string containing your hostname (massive handwave about what that 
> 
> actually means), try
> 
> 
> 
> >>> socket.gethostbyname_ex(name)
> 
> 
> 
> and see how long that takes and what it returns.  At least at that point 
> 
> you'll have cut the problem in half.
> 
> 
> 
> If I had to guess, you've got a missing PTR record, because that's what 
> 
> most people screw up.




More information about the Python-list mailing list