HomeController/Index 中的异步控制器
由于索引是网站的默认登陆区域,因此将家庭控制器设置为异步控制器是个好主意吗?
在什么场景下我可以利用AsyncControllers?
谢谢,
瑞安
since Index is the default landing zone for a website, is it a good idea to make the home controller an async controller?
In what scenario can I take advantage of AsyncControllers?
Thanks,
Ryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这不是一个好主意。
当您执行密集型 I/O 任务并且您可以从 I/O 完成端口(例如数据库调用、Web 服务调用等)受益时,我建议您阅读 以下文章可以更好地理解这个概念。它是关于异步 ASP.NET 页面,但异步控制器的工作原理完全相同。
No, it isn't a good idea.
When you have actions that perform intensive I/O tasks and for which you could benefit from I/O Completion ports such as database calls, web service calls, ... I would recommend you reading the following article for better understanding the concept. It's about async ASP.NET pages but async controllers work exactly the same.
仅当操作需要很长时间才能完成时才应使用异步控制器。异步并不会神奇地提供更好的性能,事实上,它的性能比普通控制器更差。
然而,异步控制器允许您更好地利用资源,特别是线程池。使控制器异步允许线程返回到线程池以服务其他请求。
如果您的请求没有执行任何耗时的操作,那么您只是无缘无故地增加了开销。
You should only use asynch controllers when an operation will take a long time to complete. Asynch does not magically give better performance, in fact, it will perform WORSE than a normal controller.
Asynch controllers, however, allow you to make better use of resources, in particular the thread pool. Making a controller asynch allows the thread to be returned to the thread pool to service other requests.
If your request doesn't do anything time consuming, then you're just adding overhead for no reason.