« Previous Next »

Thread: Bitrate throttling and out of memory issues

Last post 05-07-2009 3:43 AM by samzhang. 12 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (13 items)

Sort Posts:

  • 07-24-2008, 12:01 AM

    Bitrate throttling and out of memory issues

    This could be a bit complicated to explain and understand so I'll try my best to explain the set up.

     Our media files (videos) are Flash video (.flv) files. These files are not directly accessible as a url that end with a .flv. As a result the bit rate throttling module does not intercept requests for these files automatically.

    We had been using an IHttpHandler to serve these files because we authenticate the request coming from our site and from our video player before we issue the bytes. We read 8k chunks and write them directly to the OutputStream. This was working just fine, even for large files.

     We then modified the handlers to incorporate the Bitrate throttling logic. The implementation works as expect, in terms of the burst and then throttling. However there is one thing I don't like about the we the bitrate throttling has been implemented and then there is an issue we're having to do with "Out Of Memory".

     The one thing I don't like is that the http headers now include the bit rate information. These headers are visible across the internet and at the client. I don't believe there is any reason for this to be the case. I mean what's happening on the server end should remain at the server end (What happens in Vegas, stays in Vegas).

    The bigger issue is that now the server is running out of memory each time we serve large files. This was not the case when there was no bitrate throttling in place. So it looks like IIS is buffering the bytes the handler issues (in a tight loop wirting 8K chuncks) because it is throttling the serving of these bytes. So if we're issuing a large file 800MB, the process is accumulating the bytes and eventually the process is out of memory.

     The server has 8GB of memory and and at any time about 4GB is used (it kind of stays at this level) but we still see out of memory issues now.

    My question is if IIS were to handling issuing the files itself, would this problem dissapear? Second, given the situation I mention at the start, is there a way we can still get IIS to issue the media files directly, *after* we authenticate the request? Also users should not be able to request these files directly using a url that ends with a .flv, we'd still like to intercept these requests and authenticate before allowing the files to be served.

    I'm going to be trying an IHTTPModule that will intercept these requests and authenticate if the request is for our media files and allow or disallow. Does that sound ok?

    The main issue (out of memory), is that "as designed"?

  • 07-24-2008, 1:15 AM In reply to

    Re: Bitrate throttling and out of memory issues

    I should add the following:

    1. Eventually, the "Service is unavailable". We have a special app pool for our app/website this app pool is set up to allow for 4 worker processes. (server is dual - quad core, 3 GHz, 8GB). We have to reset the app pool to get it working again.

    2. Whe monitoring the worker processes using task manager I cna see the memory go from 32,000K to 930,000K while serving a file. The file is just 304,000K in size.

    3. If I use Request.WriteFile(xxx, false) I'll see the same thing happen and then an exception message such as the following:

     

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80070008): An error occurred while communicating with the remote host. The error code is 0x80070008.]
       System.Web.Hosting.IIS7WorkerRequest.FlushCore(Boolean keepConnected, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32[] bodyFragmentTypes) +2511574
       System.Web.Hosting.IIS7WorkerRequest.FlushCachedResponse(Boolean isFinal) +411
       System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +629
       System.Web.HttpRuntime.FinishRequestNotification(IIS7WorkerRequest wr, HttpContext context, RequestNotificationStatus& status) +188
    

     

  • 07-24-2008, 4:49 AM In reply to

    Re: Bitrate throttling and out of memory issues

    So in order to be able to "authenticate" a request for a media file, or in other words intercept a request for a media file I had to do the following:

    1. Define a handlers in the web.config file for the media type files (*.wmv, *.mov, *.mp4, *.flv, *.mpg etc.) One handler for each media type. This makes IIS send the request into the ASP.NET pipeline so ASP.NET code can intercept/handle the request.

    2. Define an HttpModule that essentially intercepts request for files in certain folders. If the path matches, it then authenticates the request and if allowed, does a ReWritePath to the actual folder where the media file resides. This is a virtual folder.

    In principal this works. There are a number of issues I have to yet circumvent due to the design of the actual system in as far as locations to media files and actually being able to now make them valid urls so IIS can serve the request.

     Doing it in this way does not impact the memory used by the w3wp.exe process handling the request.

  • 07-24-2008, 11:33 AM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Bitrate throttling and out of memory issues

    You could also use TransmitFile rather than WriteFile to write the media files - the problem really is that you handler is reading the whole media file into memory and with bit-rate throttling, it will remain in memory for a while - TransmitFile just uses the file-handle, so pieces of the file will be read as needed.

    Also, you do not need to do the complicated handler/mapping/rewritepath if you are running in integrated mode - just registering a managed module without the managedHandler pre-condition will invoke it for all requests.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-24-2008, 1:09 PM In reply to

    Re: Bitrate throttling and out of memory issues

    Hi Anil,

     I got the Transmit file part and will try that.

    I don't quite follow the managedHandler pre-condition part. The app is running in Integrated mode. Could you please explain.

    We develop and test under XP/IIS 6.0 and Vista/IIS 7.0. So far we've gotten by with duplicate entries in the web.config. Will htis still work?

  • 07-24-2008, 10:19 PM In reply to

    Re: Bitrate throttling and out of memory issues

    Anil,

    The TrasmitFile helps take away the memory load from the w3wp process. So we're good to go. I changed a few other handlers to use TransmitFile as well.

     I'd love to understand your previous comment to do with Integrated mode and stuff. I hope you explain or point me in the right direction.

     Thanks.

  • 07-25-2008, 3:53 AM In reply to

    • JackFree
    • Not Ranked
    • Joined on 03-17-2008, 10:23 PM
    • Redmond, WA
    • Posts 7

    Re: Bitrate throttling and out of memory issues

    If possible can you share a snippet of the HTTP headers that contain bit rate info?

    If absent the bitrate throttling module will add a Content-Length response header, but that is the only header it will potentially modify.  We do not remove or modify any headers, nor do we add any headers that would contain information about the bitrate of the content.

    Hopefully a netsniff will help get to the bottom of this.  :)


    Thanks,

    Jack

  • 07-25-2008, 4:46 AM In reply to

    Re: Bitrate throttling and out of memory issues

    Hi Jack,

     Thank you for your reply. Our system send us an email for exception and in the email we capture verious kinds of information (to help us track the issue) and I remember seeing the http headers. The items in question were the very same headers one sets using SetServerVariable when handling the throttling ourselves.

    I'll do some sniffing and get back to you on this.

     

    Shiv.

  • 07-25-2008, 12:57 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Bitrate throttling and out of memory issues

    If you need to support IIS6.0, you need to support classic mode anyway since there is no integrated mode in IIS6.0 - in integrated mode, you can just have a managed module that fires for all requests (when you add your module to system.webServer/modules, just don't add the preCondition="managedHandler" attribute) - now, you do not need to do any funky url rewriting and can do your stuff and still let IIS static file handler serve the request.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-25-2008, 1:26 PM In reply to

    Re: Bitrate throttling and out of memory issues

    Anil,

    Ok, I think I get it now. If I don't set the preCondition="managedHandler" than the module behaves like an ISAPI filter would in that as long as the request is for the app in question, the module gets fired?

  • 07-25-2008, 1:30 PM In reply to

    Re: Bitrate throttling and out of memory issues

    Jack,

    Ok, I think I assumed something here to do with headers. I did see the information in the exception email. But I saw it information in the server variables section and not in the http headers section. Since the email is sent from the system it has access to all this information, but the client does not.

    I did sniff the traffic and found that these server variables are not visible as headers or anything else. Sorry for the false alarm.

     

  • 05-06-2009, 7:52 PM In reply to

    • mbaocha
    • Top 150 Contributor
    • Joined on 04-21-2009, 8:38 PM
    • Posts 35

    Re: Bitrate throttling and out of memory issues

    May I know the version of IIS you are using for these Apps?

     

    ______________________________________________

     

    Cheap Affordable Web Hosting | Windows Linux PHP ASPX MYSQL Website Hosting | Best Web Design Company

     

  • 05-07-2009, 3:43 AM In reply to

    Re: Bitrate throttling and out of memory issues

    IIS Media Services (previously known as IIS Media Pack) is supported on IIS7.

    Thanks,

    -Sam
Page 1 of 1 (13 items)
Microsoft Communities