Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53397

Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

Newsgroups comp.lang.python
Date 2013-08-31 21:51 -0700
References <b9f77b6f-3a65-407a-aff5-5677be2ba228@googlegroups.com> <roy-F5C43B.21010031082013@news.panix.com>
Message-ID <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> (permalink)
Subject Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)
From anntzer.lee@gmail.com

Show all headers | View raw


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@googlegroups.com>,
> 
>  anntzer.lee@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-08-31 17:03 -0700
  Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Roy Smith <roy@panix.com> - 2013-08-31 21:01 -0400
    Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-08-31 21:51 -0700
      Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Michael Torrie <torriem@gmail.com> - 2013-08-31 23:06 -0600
        Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-09-01 10:13 -0700
      Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Roy Smith <roy@panix.com> - 2013-09-01 06:57 -0400
  Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Chris Angelico <rosuav@gmail.com> - 2013-09-01 21:37 +1000
    Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-09-01 13:37 -0700
      Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Chris Angelico <rosuav@gmail.com> - 2013-09-02 07:03 +1000
        Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-09-01 22:28 -0700
          Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Chris Angelico <rosuav@gmail.com> - 2013-09-02 20:42 +1000
          Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Roy Smith <roy@panix.com> - 2013-09-02 08:45 -0400
            Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) anntzer.lee@gmail.com - 2013-09-02 10:52 -0700
              Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) Chris Angelico <rosuav@gmail.com> - 2013-09-03 07:12 +1000

csiph-web