简体   繁体   English

如果我必须每次都等待而不是使用Sync .ToList(),使用.ToListAsync的各个多数据库查询是否有任何性能优势?

[英]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.

相关问题 现在我们有了“await”关键字,使用 ContinueWith 方法有什么好处吗? - Now that we have an “await” keyword, is there any benefit to using ContinueWith method? 直接处理字符串而不是将其分配给var有什么好处? - Is there any benefit of working on string directly rather than assigning it to a var? 使用不带 ToListAsync() 的 await 的实体框架 - Entity Framework using await without ToListAsync() 在公共程序集中使用 DTO 而不是对实体的共享引用是否有好处? - Is there a benefit to using a DTO rather than a shared reference to Entities in a common assembly? 在没有中间工作的情况下使用等待异步方法有什么好处? - Is there any benefit in using await with an async method without intermediate work? 如果我在未定义为任务的 IQueryable 上使用 await + ToListAsync() 是否正确 - Is it correct if i am using await + ToListAsync() over IQueryable which is not defined as a task 为什么我必须为异步查询多次编写等待? - Why do I have to write await multiple times for an async query? “ToListAsync()”和“AsAsyncEnumerable().ToList()”之间的区别 - Difference between "ToListAsync()" and "AsAsyncEnumerable().ToList()" async / await中的多个查询(错误:IEnumerable不包含ToListAsync()) - Multiple queries in async/await (Error: IEnumerable does not contain ToListAsync()) 在c#中的字段上使用const或readonly修饰符有什么性能优势? - Is there any performance benefit in using const or readonly modifiers on fields in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM