开发者

Download server with ASP.NET how to accomplish long running synchronous requests?

My ASP.NET application is a download application (no pages) which reads huge binary files (1-2 GB -> over 1 hours download time with resume support) from local network and stream them to web clients (each request -> one large binary response, so there's no text/html response at all). I use a HTTP Handler (.ashx) instead of a (.aspx) page for processing requests. Using a shared buffer and producer-consumer pattern main thread (from ASP.NET thread pool)开发者_高级运维 creates another thread and together they accomplish the job. At the end both threads exit (get back to pool).

So I have long-running request using threads from thread pool which is not recommended generally but I don't have any page in my application, is it still a bottleneck using threads from ASP.NET thread pool ?

Environment: server 2008 64bit, IIS 7.0 and .NET 4.0

What considerations should be taken for this scenario ? Any comment is appreciated.


As I explained here, just use IHttpAsyncHandler implementation in ASHX to launch a custom thread and finish with processing inside asp.net thread (thus returning it to the pool). Using this you can initiate thousands of downoads per second without running out of asp.net thread pool threads. (How and if you wish to serve that many requests is another topic of discussion)

Edit: just don't forget to call asyncRequestState.CompleteRequest() at the end of your thread, otherwise asp.net won't know that you are done serving the request.


If you are using threads from the ASP.NET pool to serve these files, you will quickly hit a hard limit of concurrent downloads, regardless of bandwidth available. It doesn't matter what the threads are doing; if they are all busy/blocked, other requests will not be able to be fulfilled.

With such a long period of time, it's also possible you could have other trouble without careful configuration; downloads could end up getting canceled, and the application could needlessly get reset.

What is the reason for serving these files via ASHX handlers?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜