问题
I have a web api 2 endpoint that talks to a service class. The service class makes calls to Entity Framework (v6)
I have applied async await on the methods where im writing to the database, querying etc.. using SaveChangesAsync(), etc
My question is regarding the overhead..
the fact i have to apply async on the method signature in the service means i then have to apply await and async on any calling method in order to compile.
The fact im sprinkling async & await on methods calling the service method - does this result in a lot of extra overhead? i.e.: my web api 2 endpoint now has async await applied to it as im calling this service method that has async & Task applied on it signature too.
The overhead i talk about is related to this article https://www.simple-talk.com/dotnet/.net-framework/the-overhead-of-asyncawait-in-net-4.5/
回答1:
It results in some overhead, yes. Normally, it is not a concern. If you expect less than 1M tasks per second I would not think about this at all.
The biggest cost of using "async all the way" is that it infects a lot of code and impacts code quality. It can increase development cost and decrease software quality because it tends to be more error prone.
来源:https://stackoverflow.com/questions/37861864/async-await-usage-and-overhead