[英]Is there any performance benefit in respective multiple db query with .ToListAsync if i have to await each time rather than using Sync .ToList()?
So I was first retrieving data from a database in this manner respectively with each entity repo: 因此,我首先以这种方式分别从每个实体仓库中检索数据库中的数据:
_dbset.ShareCompany.ToList();
_dbset.SourceOfIncome.ToList();
Likewise there were more db calls. 同样,有更多的数据库调用。 Then I changed my db call to:
然后我将数据库调用更改为:
await _dbset.ShareCompany.ToListAsync();
await _dbset.SourceOfIncome.ToListAsync();
But I do not think that there is any performance benefit with this async call as it has to wait for the data to be retreived, which actually in turn makes it into sync call. 但是我不认为此异步调用有任何性能上的好处,因为它必须等待数据取回,这实际上又使它成为同步调用。 If I have to wait for the data in order to retrieve my next data.
如果我必须等待数据才能检索我的下一个数据。
So if anyone could tell me when is it a good practice to use async calls and will there be any performance benefit if I use async in my second code and how? 因此,如果有人能告诉我什么时候使用异步调用是一种好习惯,并且如果我在第二个代码中使用异步,以及如何使用异步调用,将会对性能产生任何好处?
Using async will release your worker thread for accepting new requests. 使用异步将释放您的工作线程以接受新请求。 This makes your application more responsive.
这使您的应用程序响应速度更快。 If you do not use async, the worker thread is blocked and IIS will spin-up a new thread for new requests (which eventually may hamper performance of application as you can spin up only so many threads).
如果不使用异步,则工作线程将被阻止,并且IIS会为新请求启动一个新线程(由于只能启动这么多线程,最终可能会妨碍应用程序的性能)。
This is actually duplicate of this question which has already been answered. 这实际上是已经被回答的这个问题的重复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.