将多个HTTP请求等待同一个I/O完成端口

发布于 2024-12-18 07:58:28 字数 540 浏览 2 评论 0原文

我的应用程序从 Web 服务和“Application_Start”异步加载大量信息。

如果用户请求想要使用该信息,但它还没有准备好,则线程将被 Monitor.Wait 阻塞。当信息准备好时,缓存对象将Monitor.Pulse所有等待的线程。这应该没问题,因为信息需要十几秒,并且用户必须重定向到登录页面,发布登录信息,然后再次重定向。

问题是 Monitor.Wait 会阻塞 CLR ThreadPool 线程,据我所知,如果请求“大信息”的突发请求到达,应用程序可能会因 CLR ThreadPool 饥饿而保持阻塞状态(我有点混乱)与当前的 IIS/ASP.NET 线程门控)。

由于大量信息来自我异步调用的 Web 服务,因此我拥有该操作的 IAsyncResult。

那么,有没有办法告诉 CLR ThreadPool 线程“等待这个 IOCP”,以便线程池线程可以开始参加其他调用?

我觉得这没有得到很好的解释,如果不清楚我在问什么,请告诉我。

问候。

PS:虽然赏金已经结束,但如果有人知道一种方法,我会提出一个新的方法并授予作者。

My application load asynchronously a big amount of information from a web service and "Application_Start".

If an user request wants to use that information, and it is nor ready, the thread will be block with a Monitor.Wait. When the information is ready, the cache object will Monitor.Pulse all waiting threads. This should be fine, since the information takes a dozen of seconds, and the user has to be redirected to the login page, post login information, and be redirected again.

The problem, is that Monitor.Wait will block the CLR ThreadPool thread, and as far as I know if a burst of requests arrives asking for the "big information", the application could remain block by CLR ThreadPool starvation (I have a little mess with the current IIS/ASP.NET thread gating).

Since the big piece of information comes from a web service that I call asynchronously, I have the IAsyncResult of that operation.

So, Is there a way to tell a CLR ThreadPool Thread "Wait for this IOCP", so the threadpool thread can start to attend other call?

I have the feeling that this is not well explained, let me know if it is not clear what I am asking.

Regards.

PS: Although the bounty is over, if anybody knows a way to do that I will raise a new one and grant the author.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最舍不得你 2024-12-25 07:58:28

这是一个很好的问题。我的经验是,你尝试干扰 ASP.NET 内部的次数越多,造成的痛苦就越多。

您是否考虑过使用 serviceAutoStartProviders 来保持您的应用程序热度?

ASP.NET 4.0:如何使用应用程序预热类

This is a great question. My experience has been to more you try to interfere with ASP.NET internals the more pain you cause.

Have you considered using serviceAutoStartProviders to keep your app hot?

ASP.NET 4.0: How to use application warm-up class

梦里兽 2024-12-25 07:58:28

您应该使用 IHttpAsyncHandler 来返回加载缓慢的大数据。
演练:创建异步 HTTP 处理程序

在处理异步 HTTP 处理程序期间,ASP.NET
通常用于外部进程返回的线程
进入线程池,直到处理程序收到来自线程池的回调
外部流程。这样可以防止线程阻塞并提高
性能,因为只能执行有限数量的线程
同时。


IHttpAsyncHandler 返回 12 秒应该没有问题。事实上,您应该能够轻松地达到 60 秒左右,无需担心。除此之外,您可能需要实现某种类型的 long-轮询系统来监控系统状态。

IHttpAsyncHandler 可以返回 XML/JSON 或您喜欢的任何内容。您可以通过 javascript 中的 ajax(可能是 jQuery.ajax)甚至服务器端使用 IHttpAsyncHandler如果您想使用 HttpWebRequest(一些示例 C# 代码:调用远程 JSON Web 服务)。

You should be using IHttpAsyncHandler to return your slow loading big data.
Walkthrough: Creating an Asynchronous HTTP Handler

During processing of an asynchronous HTTP handler, ASP.NET puts the
thread that would ordinarily be used for the external process back
into the thread pool until the handler receives a callback from the
external process
. This can prevent thread blocking and improve
performance, because only a limited number of threads can be executing
at the same time.

You should have no problem taking 12 seconds to return from an IHttpAsyncHandler. In fact you should be able to easily go up to about 60 seconds, without worry. Beyond that you may need to implement some type of long-polling system to monitor system status.

The IHttpAsyncHandler can return XML/JSON or whatever you like. You can consume the IHttpAsyncHandler via ajax in javascript (maybe jQuery.ajax) or even server side if you want using an HttpWebRequest (some sample C# code: Calling remote JSON webservice).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文