Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ASP.NET MVC's AsyncController be used to service large number of concurrent hanging requests (long poll)?

Frameworks like Node.js, Tornado, and Twisted let developers create server-push applications that supports large number of concurrent hanging requests (10k+). From what I understand, they all achieve this by not creating threads to service each hanging request.

Can AsyncController be used to service large number of inactive concurrent requests?

If so, are there any reasonably large ASP.NET MVC websites using this approach to create long-poll applications?

like image 418
David H Avatar asked Feb 13 '11 06:02

David H


People also ask

Can ASP net Core handle many requests?

ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.

What is sync and async in .NET core?

Async only buys you anything if your server is at load. It's only at times when your server is stressed that async will give it some much needed breathing room, whereas sync might bring it to its knees. It's all about scale.


1 Answers

AsyncController is useful (compared to a normal controller) in the following situation:

You have a long running task and this task is normally achieved by some other tier (web service, database, ...) by using I/O Completion Ports. So the request starts on a worker thread, then you call the BeginXXX method which will open an IOCP (if it supports it, if not it is useless as it will simply draw another worker thread) and the worker thread will be immediately returned to the thread pool. During the execution of the long operation no worker threads are being consumed on the server. Once it completes it signals the IOCP, the async controller draws another thread from the pool to simply terminate the request and return the results to the view. There are a few things to note here: the fact that you used an async controller instead of a normal controller makes absolutely no difference to the client: he will still need to wait the same amount of time for the request to finish, don't get the false impression that an async controller will make your slow operation run faster. Simply the worker threads will be monopolized for less time and so potentially making other requests run faster.

To sum up: for fast running requests async controllers won't bring you any benefit compared to normal controllers. For slow requests they could but it will depend on the nature of the long running operation and whether it is CPU or I/O bound. For CPU bound tasks async controllers are not more useful either. But in all cases you should perform extensive load testing on your application.

Here's a very good article on MSDN which explains async requests in ASP.NET.

And here's a blog post which illustrates how an async controller could be used to implement long-polling.

like image 157
Darin Dimitrov Avatar answered Sep 30 '22 01:09

Darin Dimitrov