简体   繁体   English

.Net中的异步Web请求是否有助于提高性能

[英]Does an asychronous web request in .Net help performance

C#.net中的常规请求与异步请求之间的性能差异(如果有)是什么?

Depends on your use case. 取决于您的用例。 While there is no immediate performance benefit from using async in simple scenarios, it can be crucial in more complex ones, and for scalability. 尽管在简单的场景中使用异步并不会立即带来性能上的好处,但对于更复杂的场景和可伸缩性而言,这可能至关重要。

For instance, sending multiple requests to many servers is obviously best done in parallel, this can be handled using async. 例如,向多个服务器发送多个请求显然最好并行完成,这可以使用异步处理。

Regarding scalability, consider a web application that uses sync web requests to communicate with slow external servers. 关于可伸缩性,请考虑使用同步Web请求与速度较慢的外部服务器进行通信的Web应用程序。 Since IIS only allocates a limited amount of threads to serve requests from users, when the number of users grow, there is a risk that all user threads will be blocked while waiting for the external web requests. 由于IIS仅分配有限数量的线程来满足来自用户的请求,因此当用户数量增加时,存在所有用户线程在等待外部Web请求时将被阻止的风险。 This means that some user requests will be rejected by IIS. 这意味着某些用户请求将被IIS拒绝。

It depends, in asp.net you must use synchronous (until 4.5); 这取决于在asp.net中必须使用同步(直到4.5); but in a Windows Form or any other type of C# project though, it prevents the thread from being on hold. 但是在Windows窗体或任何其他类型的C#项目中,它可以防止线程处于保留状态。 Calling the ASYNC complete event, would allow you to update the proper information without putting the UI or the Main thread on hold. 调用ASYNC complete事件,将允许您更新适当的信息,而无需将UI或Main线程置于保留状态。

在异步模式下,服务器只能回复您想要的内容,这将最大程度地减少网络流量,然后最小化响应时间,改善用户体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM