locked
Throttle the data reading rate for IXMLHTTPRequest2

    Question

  • I recently did a test and it seems the behavior of IXMLHTTPRequest2 is to read the entire document over http as fast as possible, regardless of size/space consumed.

    I am trying to read a multimedia stream with the interface and so I want to process the data at the appropriate speed - for instance, if I am playing a video 1Mb/s video stream, I only want to consume the data at 1Mb/s (on average).

    Seems IXMLHTTPRequest2 prefers to read the whole video into memory as fast as possible (2GBytes) and the machine grinds to a halt as I've consumed all it's RAM.

    Is there a way to throttle the read rate with this interface?

    Thanks,

    Rik.

    Thursday, February 13, 2014 11:55 PM

Answers

All replies

  • I think you'd be better off using a StreamWebSocket so you can handle each section of incoming stream at your leisure:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh761442.aspx


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, February 14, 2014 2:08 PM
    Moderator
  • There is not.  You would need to implement your own socket code to do something specialized like that.

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, February 14, 2014 2:08 PM
    Moderator
  • I'll take a look at that thanks.

    Reading the API for IXMLHttpRequest, I was also wondering if it's possible to use the SetCustomResponseStream on IXMLHttpRequest, to customize the behavior of the stream receiving the HTTP response.

    Then in the implementation of the ISequentialStream::Write() could we block (or return zero in pcbWritten) to throttle the read.

    The documentation advises that Write() should *not* do any heavy processesing because it is called "... inline to receiving further data ...", so degrading throughput, but that's actually what we are trying to achieve.

    As long as we only block the read on our own socket (not all network traffic) it should be a good approach.

    Friday, February 14, 2014 6:01 PM
  • Hi UK,

    You may be able to use write and return E_PENDING

    I don't remember internally what that would do to the underlying socket but give it a shot.  If you want to go down that road and run into problems, that is an advanced topic that you could bring up with the Internet Explorer support team through a support case.

    Jeff


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, February 14, 2014 7:17 PM
    Moderator
  • The StreamWebSocket is unlikely to help (and unless the server supports web sockets, won't even work).

    If you use the Windows.Web HttpClient, you can read the results as a stream; this might provide the control you're looking for.

    Regardless of anything else, it's the sender that's sending the data at a high rate; you might not be able to control the server the way you want. If the server supports byte ranges, you might get by with sending a series of requests for a set of byte ranges.  This might have other issues, of course (in particular: at least some CDNs don't cache resources with byte ranges)


    Network Developer Experience Team (Microsoft)

    Friday, February 14, 2014 7:53 PM
  • Are there any examples of using the "SetCustomResponseStream"?  I am now trying to do this, and I get the error code "c00c023e" when I try to set my response stream.

    I don't see that particular error code documented anywhere.

    Thanks,

    Rik.

    Wednesday, June 11, 2014 1:22 AM
  • The Weathr sample does HttpRequest throttling. Does this help? https://weathr.codeplex.com/SourceControl/latest#Weathr/HttpRequestThrottler.cpp
    Friday, July 04, 2014 3:32 PM
  • Hi Michael,

    That's a different type of throttling (if I understand the code correctly).  They are limiting the number of requests that the client makes to the server. Presumably there client could be making tens of concurrent requests.

    In our case, we are only making a single request, but the size of the response is large, and we don't want the server to reply using all the bandwidth available to the console, we want to limit the speed of the response to a few megabytes/second, as that is the speed at which we use the data.

    Thanks,

    Rik.

    Monday, July 07, 2014 9:32 PM
  • I see now. You are correct about the Weathr code. Sorry for the misunderstanding!
    Tuesday, July 08, 2014 7:00 PM