Why use asynchronous controllers when IIS is already processing a concurrency request?

I wonder why I should worry about using async Task on controllers when IIS already handles concurrency for me?

http://msdn.microsoft.com/en-us/library/dd560842.aspx

+7
asynchronous asp.net-mvc iis task-parallel-library
source share
3 answers

Async / await in asp.net is not about concurrency, it's about blocking or not blocking threads.

If you use async / wait, you release the thread while you wait for the operation. If this operation is CPU related, there is no benefit (it will be a little slower due to context switching)

If the operation is limited to IO (network, disk, ...), this means that IIS can handle more parallel requests, since you are not blocking threads that do nothing.

+13
source share

As others have pointed out, async allows the request thread to return to the thread pool when performing an asynchronous operation. When using synchronous handlers, your server will have threads blocked during I / O, essentially doing nothing important, but also cannot be used for other requests while they are blocked. async just frees these threads so they are useful all the time.

So, the first thing to note is the question “ async or thread pool”. When you use async , you allow ASP.NET to make the most of the existing thread pool. async accepts existing (parallel) concurrency in ASP.NET and adds (asynchronous) concurrency to achieve greater scalability.

But the question remains "why"? The reasons are twofold: async can scale further (just) the thread pool, and async also more sensitive. As mentioned in the comments to other answers, threads are quite heavy objects that lose unnecessary pleasure; the memory for asynchronous operations is much less than that used by the thread. The second reason is also important: when a sudden surge in requests arrives, the thread pool (by itself) can only expand at a limited rate; async allows a thread pool to process request packets much more efficiently.

+10
source share

When processing a request, you are likely to gain access to resources that can take a considerable amount of time (for example, the round-trip to the database will probably be tens of milliseconds, often slower).

If you use synchronous operations to get these resources, then the processing flow is blocked until the IO completes.

Using asynchronous operations allows you to use the same IIS thread for something more useful when IO completes. On websites with a higher load, this can be a significant difference in scalability.

+2
source share

All Articles