tags:

views:

396

answers:

2

I promise this isn't as simple as it sounds. I'm wondering why the the first ever call to HttpSendRequest takes much longer than subsequent calls, even when the later requests are for a different URL. For example:

InternetConnect(... "foo.com" ...) // returns immediately
HttpOpenRequest(...) // returns immediately
HttpSendRequest(...) // takes ~3 sec
HttpSendRequest(...) // takes ~200 ms

InternetConnect(... "bar.com" ...) // returns immediately
HttpOpenRequest(...) // returns immediately
HttpSendRequest(...) // takes ~200 ms

Why does the first HttpSendRequest(...) take so much longer? This is very consistent, regardless of the URLs.

Thanks, Greg

+1  A: 

There are several things that may need to happen on the first request that don't need to happen on the second. DNS lookup and proxy detection immediately come to mind.

Michael
Details: C++, Windows OS, corporate T1 internet connectivity with no proxy. So the thinking is there is some one-time DNS-lookup and proxy-detection overhead. Once completed, all subsequent requests, even to "new" domains which require a DNS resolution, would benefit. Right?
A: 

It could also be config file loading. Some of the .Net framework classes will attempt to read settings from the application config file, revertign to defaults if no file or setting is found. E.g. WebRequest/WebClient which I think are Http classes use under the hood will check for explicit web proxy settings, if those don't exist then then proxy setting from the OS (as set within IE) are picked up. Allof this contributes to an initial startup lag usually when the class is first used, that is, the work is often done in within a static contructor.

The config settings are defined here:

Configuration File Schema for the .NET Framework

locster
I'm using C++ for a desktop app (no .NET) but it certainly could be related to the proxy detection overhead and possibly also to additional class-loading. In either case it seems to be unavoidable. I'll look into making a dummy call prior to when I actually need it (on a separate thread), while waiting for user input or some other time when cycles are available.