5

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 ?

Xaqron
  • 29,931
  • 42
  • 140
  • 205
  • Binary data is received from other server via socket – Xaqron Oct 08 '10 at 12:48
  • The process is not CPU bounded but because it's lengthy, under stress test ASP.NET starves (no more thread is leaved in the pool) so clients get time out while there is enough CPU & RAM. – Xaqron Oct 08 '10 at 17:35

1 Answers1

2

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
  • 118,037
  • 53
  • 300
  • 385
  • 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 Oct 08 '10 at 15:39
  • @xaqron - what version of IIS are you on? – Kev Oct 08 '10 at 16:06
  • No limitation. I can use IIS 7.0 as it's my choice now. please check the comment I added to question. – Xaqron Oct 08 '10 at 17:37
  • @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 Oct 08 '10 at 17:55
  • 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 Oct 08 '10 at 18:22