Why does first ever HttpSendRequest take longer?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Why does first ever HttpSendRequest take longer?

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Why does first ever HttpSendRequest take longer?

    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

  2. #2
    Join Date
    Sep 2009
    Posts
    28

    Re: Why does first ever HttpSendRequest take longer?

    Get a packet capture to determine if it really is a genuine network delay, the SYN packet doesn't actually get sent until HttpSendRequest() is called. I can't see any reason why your implementation\code would delay, so might be DNS\network.

  3. #3
    Join Date
    May 2008
    Posts
    300

    Re: Why does first ever HttpSendRequest take longer?

    It uses resolved ip directly instead of requesting it from DNS the second time you send the request. And for the very first time you send the request, the whole network path might needs some preparations for your existance.

    Ah, and winhttp might use keep-alive connection (I've never used winhttp, so I don't know if it is default). In this case, the second request will be send without first connecting the server(already connected).
    Last edited by DreamShore; October 12th, 2009 at 03:30 AM.
    Nope

  4. #4
    Join Date
    Oct 2009
    Posts
    2

    Re: Why does first ever HttpSendRequest take longer?

    Thanks for the info. I forgot to mention that I'm using WinInet (not quite as good as WinHttp but needed for Windows Mobile). I thought about DNS resolution but am curious why I don't see the delay when sending to a second domain. It would have to resolve that as well. A co-worker guessed that it might be due to one-time overhead such as proxy detection and possibly initializing something for DNS resolution (i.e. maybe the DNS server itself is cached and available when sending to the second domain).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center