One of my colleagues today came to the conclusion that such code was meaningless, that it would simply create additional work for managing threads and under load, in fact, we will generate more work for the runtime and slow down the application as a result.
This is funny, as the opposite. As other responders noted, if you use true asynchronous operations (i.e. Not Task.Run or something like that), then fewer threads are used, and the application responds better to the load.
Some people (not me) did research on βmediumβ ASP.NET applications, switching to async , and they found scalability increases from 10x to 100x when switching to async as opposed to blocking calls. You can expect better scalability if your application has more asynchronous operation.
If you look at one request and if each operation is performed one at a time, then the asynchronous version is a bit slower. But if you look at the system as a whole - especially under load - the asynchronous version scales better. Another aspect of asynchronous handlers that are often overlooked is that the asynchronous version responds more quickly to sudden loads than the thread pool itself.
In addition, asynchronous code simplifies the execution of parallel queries, which also speeds up the execution of individual queries:
public async Task<SomeViewModel> Get(int id) { var someDataTask = _service.GetData(id); var someOtherDataTask = _service.GetMoreData(id); await Task.WhenAll(someDataTask, someOtherDataTask); return new SomeViewModel { Data = await someDataTask, OtherData = await someOtherDataTask, } }
source share