How much async / await is ok?

In our project, we use async / wait for almost three purposes (for all their methods):

  • Data access level: fetching / updating databases (using Dapper).
  • Cache (Redis): read / write.
  • ASP.Net MVC 5 controllers.

The question is how well is async / await. Can I use them even when reading or writing a small amount of data? What about cache and controllers?

Notes: The project is a little special, and it can have about 50,000 requests per second for several hours a day.

+6
source share
2 answers

According to the article I read:

Async / await is great for preventing blocking, although potentially time-consuming work is done in a .NET application, there is overhead associated with running the asynchronous method

The cost of this is relatively low if asynchronous operation takes a lot of time, but it is worth keeping in mind.

Based on what you requested, even when reading or writing a small amount of data? . This does not seem to be a good idea, as it is.

Here is the article: async / await overhead in NET 4.5

And in the article, he used a profiler to test the async / wait optimization.

Quote:

Despite the fact that this asynchronous method is relatively simple, the ANTS Performance Profiler shows that it has called more than 900 perspective methods to initialize it and the work that it does for the first time, its launch.

The question here may be if you are going to accept these minimum overhead costs and take into account that these overheads accumulate in something that can be problematic.

+3
source

The question is how well is async / await. Can I use them even when reading or writing a small amount of data? What about cache and controllers?

You should use async / wait for I / O binding operations, it doesn't matter if this is a small amount of data. It is more important to avoid potentially lengthy I / O operations, mainly related to disks and network calls. Asp.net has a limited thread pool size, and these operations may block it. Using asynchronous calls helps your application scale better and allows you to handle more concurrent requests.

For more information: http://msdn.microsoft.com/en-us/magazine/dn802603.aspx

+2
source

Source: https://habr.com/ru/post/978314/


All Articles