Will this always give me better scalability and/or performance?
It may. If you only have a single database server as your backend, then your database could be your scalability bottleneck, and in that case scaling your web server won't have any effect in the wider scope of your service as a whole.
How can I measure this?
With load testing. If you want a simple proof-of-concept, you can check out this gist of mine.
Why isn't this used in the "real world" a lot?
It is. Asynchronous request handlers before .NET 4.5 were quite painful to write, and a lot of companies just threw more hardware at the problem instead. Now that .NET 4.5 and async
/await
are gaining a lot of momentum, asynchronous request handling will continue to be much more common.
How about context synchronization?
It's handled for you by ASP.NET. I have an async
intro on my blog that explains how await
will capture the current SynchronizationContext
when you await
a task. In this case it's an AspNetSynchronizationContext
that represents the request, so things like HttpContext.Current
, culture, etc. all get preserved across await
points automatically.
Is it that bad, that I shouldn't use async I/O in ASP.NET MVC?
As a general rule, if you're on .NET 4.5, you should use async
to handle any request that requires I/O. If the request is simple (i.e., does not hit a database or call another service), then just keep it synchronous.