views:

89

answers:

1

Consider an ASP.NET page with this code:

while (read)
{
   Response.OutputStream.Write(buffer, 0, buffer.Length);
   Response.Flush();
}

The application should be highly performance-tuned and handle thousands on concurrent requests and the main purpose is transferring huge binary file to clients over high speed connections. I can do the job with an ASP.NET page, with HTTP Handler, IHttpAsyncHandler, ISAPI filter and ...

The question is what is the best choice for this purpose ?

+2  A: 

If the page is liable to be I/O bound then I'd go the Async road. But you should use the asynchronous read methods (if available) on your Stream object as well.

For more information see:

FileStream Constructor - with async example

To address your comment that you receive this data via a socket, you'll also find that most of the System.Net.Sockets namespace classes support asynchronous behaviour.

Kev
As I researched ISAPI filters are the fastest way but I don't know if it's possible to write one with C# and if yes, do I have any access to asp.net features like calling a webservice, etc...
Xaqron
@xaqron - what version of IIS are you on?
Kev
No limitation. I can use IIS 7.0 as it's my choice now. please check the comment I added to question.
Xaqron
@Xaqron - you don't need an ISAPI filter for this. You just need to manage your ASP.NET threads better so they're not blocking reading data from the source socket and writing to the output stream. Using Async techniques is how to achieve this.
Kev
I found an article about Async handler usage on MSDN which targets the same problem I already have (client timeout while no reurce shortage is seen -> asp.net pool saturation). But afetre reading it I have a new question. would you please take a look at it:http://stackoverflow.com/questions/3893215/how-to-configure-asp-net-thread-count-upper-limit-based-on-system-resources
Xaqron