Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top