views:

181

answers:

3

Here's what I've done:

  • I wrote a minimal web server (using Qt, but I don't think it's relevant here).
  • I'm running it on a legal Windows 7 32-bit.

The problem:

  • If I make a request with Firefox, IE, Chrome or Safari it takes takes about one second before my server sees that there is a new connection to be accepted.

Clues:

  • Using other clients (wget, own test client that just opens a socket) than Firefox, IE, Chrome, Safari seeing the new connection is matter of milliseconds.
  • I installed Apache and tried the clients mentioned above. Serving the request takes ~50ms as expected.
  • The problem isn't reproducible when running Windows XP (or compiling and running the same code under Linux)
  • The problem seems to present itself only when connecting to localhost. A friend connected over the Internet and serving the connection was a matter of milliseconds.
  • Running the server in different ports has no effect on the 1 second latency

Here's what I've tried without luck:

  • Stopped the Windows Defender service
  • Stopped the Windows Firewall service

Any ideas? Is this some clever 'security feature' in Windows 7? Why isn't Apache affected? Why are only the browsers affected?

+2  A: 

You may be running into some automatic proxy discovery problem. In Firefox, you can disable this in Options | Advanced | Network | Settings; select either "No proxy" or give it explicit values. There's also the Internet Properties control panel, which is IE's network settings, but other browsers on Windows may obey settings here, too. Again, disable auto-proxy discovery. This can speed connections outside localhost, too.

Warren Young
+2  A: 

If you're saying "localhost" instead of "127.0.0.1", you're forcing a name lookup before the actual connection attempt, adding delay.

In addition, some browsers, like Firefox 3.5+, don't use the operating system's DNS lookup mechanism, which is why it can have different performance than, say, wget.

Warren Young
A: 

For some reason Windows 7 takes 1 second to resolve address localhost regardless of it being in hosts file.

Adding localhost1 to hosts file and using that works around the problem.

Petri Sirkkala