Async await usage and overhead [closed]

元气小坏坏 提交于 2020-01-04 06:53:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!