同步HTTP处理程序和异步HTTP处理程序之间的性能差异 [英] Performance difference between Synchronous HTTP Handler and Asynchronous HTTP Handler

查看:232
本文介绍了同步HTTP处理程序和异步HTTP处理程序之间的性能差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有同步HTTP处理程序和异步HTTP处理程序之间的性能差异?
IHttpHandler的VS IHttpAsyncHandler

Is there a performance difference between Synchronous HTTP Handler and Asynchronous HTTP Handler? IHttpHandler vs IHttpAsyncHandler

为什么选择一个比另一个?

Why choose one over another?

有什么好处?

推荐答案

ASP.NET使用线程池来处理传入的HTTP请求。

ASP.NET uses the thread pool to process incoming HTTP requests.

当一个IHttpHandler的被调用时,一个线程池线程用于运行该请求,并在同一个线程来处理整个请求。如果该请求调用到数据库或其它Web服务或其他任何可能需要一段时间,线程池线程等待。这意味着线程池中的线程花费时间等待的事情时,他们可以用来处理其他请求。

When an IHttpHandler is called, a thread pool thread is used to run that request and the same thread is used to process the entire request. If that request calls out to a database or another web service or anything else that can take time, the thread pool thread waits. This means thread pool threads spend time waiting on things when they could be used to process other requests.

在相反,当一个IHttpAsyncHandler,一个机制来允许请求注册的回调和线程的线程池返回到池之前请求被完全处理。线程池线程开始做一些处理的请求。也许调用数据库调用或Web服务或一些东西异步方法,然后注册了ASP.NET的时候调用调用返回的回调。在这一点上,这是处理HTTP请求的线程池线程返回到池来处理另一HTTP请求。当数据库调用或其他不回来,ASP.NET触发注册的回调在一个新的线程池线程。最终的结果是你没有线程池中的线程等待I / O密集​​型操作,你可以更有效地使用线程池。

In contrast, when an IHttpAsyncHandler, a mechanism exists to allow the request to register a callback and return the thread pool thread to the pool before the request is fully processed. The thread pool thread starts doing some processing for the request. Probably calls some async method on a database call or web service or something and then registers a callback for ASP.NET to call when that call returns. At that point, the thread pool thread that was processing the HTTP request is returned to the pool to process another HTTP request. When the database call or whatever does come back, ASP.NET triggers the registered callback on a new thread pool thread. The end result is you don't have thread pool threads waiting on I/O bound operations and you can use your thread pool more efficiently.

有关非常高并发应用程序(真正的用户同时使用的数百或数千),IHttpAsyncHandler可提供并发巨大的推动作用。与用户的数目较少,但仍然可以是一个好处,如果你有非常长的运行的请求(如长轮询请求)。然而,IHttpAsyncHandler下编程较为复杂,所以当不真正需要它不应该被使用。

For very high concurrency applications (hundreds or thousands of truly simultaneous users), IHttpAsyncHandler can provide a huge boost in concurrency. With a smaller number of users, there can still be a benefit if you have very long running requests (like a Long Polling request). However, programming under the IHttpAsyncHandler is more complicated, so shouldn't be used when it isn't really needed.

这篇关于同步HTTP处理程序和异步HTTP处理程序之间的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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