我应该用保鲜Task.Run缓慢的电话? [英] Should I wrap slow calls with Task.Run?

查看:104
本文介绍了我应该用保鲜Task.Run缓慢的电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的ASP MVC调用这是因为aync一个异步的调用它需要做出。我注意到有几个慢速同步调用(例如数据库访问)的。该方法需要有才能继续提供的所有返回的数据。

I have this ASP MVC call which is aync because of an async call it needs to make. I noticed there are a couple of slow sync calls (e.g. db access). The method needs to have all returned data available in order to proceed.

我想用包装的Task.Run同步调用并等待为他们所有。

I thought of wrapping the sync calls with Task.Run and await for all of them.

是否有意义包裹慢同步电话?如果当时只有同步电话?

Does it make sense to wrap the slow sync calls? What if there was only sync calls?

推荐答案

不要使用 Task.Run 在服务器端code并行工作,除非客户端的请求数你希望成为同时真的很低。否则,你可能会加速个人请求的处理,但你会伤害你的web应用程序可扩展性,当有很多用户的。

Don't use Task.Run to parallelize work in the server-side code, unless the number of client requests you expect to serve concurrently is really low. Otherwise, you might speed up the processing of an individual request, but you'll hurt scalability of your web app for when there are many users.

这篇关于我应该用保鲜Task.Run缓慢的电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆