bad httplib latency due to IPv6 use

Hans Mulder hansmu at xs4all.nl
Wed Oct 17 05:37:07 EDT 2012


On 17/10/12 09:55:13, Ulrich Eckhardt wrote:
> Hi!
> 
> I noticed yesterday that a single HTTP request to localhost takes
> roughly 1s, regardless of the actually served data, which is way too
> long. After some digging, I found that the problem lies in
> socket.create_connection(), which first tries the IPv6 ::1 and only then
> tries the IPv4 127.0.0.1. The first one times out after 1s, causing the
> long latency.
> 
> What I'm wondering is this:
> 1. The server only serves on IPv4, changing this to IPv6 would probably
> help. However, I wouldn't consider this a bug, or?

I'd say it's a bug in your TCP/IP stack.  An IP shouldn't take that long
to figure out that it is not configured to connect to IPv6 addresses.

> 2. I don't even have any IPv6 addresses configured and I'm not using
> IPv6 in any way, so why does it try those at all?

I have no experience with win7/64, but on earlier versions of Windows,
there's a file named "hosts", somewhere in a system directory.  When
looking up an IP address, this file is consulted first.  Removing the
::1 from the entry for localhost might be a sensible work-around.

> 3. Of course I can optimize the code for IPv4, but then I would be
> pessimizing IPv6 and vice versa...

I'd avoid doing that, if at all possible.

> Any other suggestions?

Try "ping localhost" on the command line.  It that has the same problem,
than the problem is not in Python, but in your IP stack. It might be in
a FAQ list for some windows-specific forum.

> Notes:
>  * Using 127.0.0.1 as host works without the delay.

That make sense: it's the attempt to connect to ::1 that is the problem.

>  * I'm using Python 2.7 on win7/64bit


Hope his helps,

-- HansM



More information about the Python-list mailing list