是否异步和等待的ASP.Net应用程序的性能提高 [英] Does async and await increase performance of an ASP.Net application

查看:149
本文介绍了是否异步和等待的ASP.Net应用程序的性能提高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我读到 C#-5 和新&放的物品;漂亮的异步编程功能。我看到它在Windows应用程序马丽娟。来找我的问题是,如果此功能可以提高性能ASP.Net?

I recently read an article about c#-5 and new & nice asynchronous programming features . I see it works greate in windows application. The question came to me is if this feature can increase ASP.Net performance?

考虑这两psudo code:

consider this two psudo code:

public T GetData()
{
    var d = GetSomeData();
    return d;
}

public async T GetData2()
{
    var d = await GetSomeData();   
    return d;
}

在拥有一个ASP.Net器件的应用有两个codeS区别?

Has in an ASP.Net appication that two codes difference?

感谢

推荐答案

好了开始你的第二件code的将返回任务< T> 而不是 T 。最终的答案是看情况。

Well for a start your second piece of code would return Task<T> rather than T. The ultimate answer is "it depends".

如果你的页面需要访问多个数据源,它的可以的更简单地并行访问这些资源,利用必要的每个访问结果只有在。因此,例如,你可能想的启动的做一个长期运行的数据提取作为您的页面处理的第一部分,那么只需要在最后的结果。这显然​​可以做到这一点,而不使用异步/的await,但它是一个简单得多,当语言是帮助你。

If your page needs to access multiple data sources, it may make it simpler to parallelize access to those sources, using the result of each access only where necessary. So for example, you may want to start making a long-running data fetch as the first part of your page handling, then only need the result at the end. It's obviously possible to do this without using async/await, but it's a lot simpler when the language is helping you out.

此外,异步,可用于处理在小数量的线程长时间运行的请求数量庞大,如果大多数的请求,将闲置了大量的时间 - 例如在长轮询场景。我可以看到正在使用的异步能力作为替代 SignalR 的在某些情况下

Additionally, asynchrony can be used to handle a huge number of long-running requests on a small number of threads, if most of those requests will be idle for a lot of the time - for example in a long-polling scenario. I can see the async abilities being used as an alternative to SignalR in some scenarios.

异步电动机在服务器端的好处是难以牵制比客户端上,因为有的不同的的方式,它可以帮助 - 而避免UI线程上做的工作的一面是如此的明显,很容易看到的好处。

The benefits of async on the server side are harder to pin down than on the client side because there are different ways in which it helps - whereas the "avoid doing work on the UI thread" side is so obvious, it's easy to see the benefit.

不要忘了,可以有很多,多到服务器端编码不仅仅是前端。根据我的经验,异步是最有可能实现RPC服务时,是有用的特别是那些与多个的其他的RPC服务。

Don't forget that there can be a lot more to server-side coding than just the front-end. In my experience, async is most likely to be useful when implementing RPC services, particularly those which talk to multiple other RPC services.

由于帕西说,这只是语法糖 - 但我相信,这是足够甜的糖,它可能作出适当的处理异步是可行的,它是只是太多的精力和复杂性之间的区别

As Pasi says, it's just syntactic sugar - but I believe that it's sufficiently sweet sugar that it may well make the difference between proper asynchronous handling being feasible and it being simply too much effort and complexity.

这篇关于是否异步和等待的ASP.Net应用程序的性能提高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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