How to notify my JS client without polling?

Context: From my javascript web interface, I run a lengthy (several minutes) operation that runs on the .NET2.0 backend. The call is immediately returned with the identifier of the operation when long work is performed in parallel. Operations do not require heavy CPU utilization, but perform slow network calls. As soon as the operation is completed, I want to see the results in the web interface.

Question: How can I notify the client when the work is done?

Parameters that I reviewed:

Option 1: I start a long operation asynchronously directly from JS, and I expect the return value to be endresult instead of the operation identifier. My AJAX library takes care of everything, and life looks very easy and neat. The problem is that on the server side, the thread is a ThreadPool thread, which I now blocked for several minutes . You do not need too many lengthy parallel requests to make ThreadPool starve and bring the entire server to its knees, even if there is sufficient processing power.

Option 2: with the operation ID, I start polling the server if the operation is completed. However, this is a denial of service attack on my own server. In addition, there must be a fair ajax solution. This is not a unique issue.

+4
source share
6 answers

Check out WebSync , a comet implementation for .NET. It should be exactly what you are looking for.

+3
source

Polling, if done correctly, will not have a noticeable effect on the load on your server. You must adjust the interval to best reflect the specifics of the job on the server. You will not interrogate the server for at least 2 minutes if you know that the operation usually takes longer. Even after that, you select a sufficiently large interval - for example, 10 seconds. Using a web service request or a custom handler minimizes the traffic and server time required to process the request.

+3
source

Perhaps reverse ajax is useful if you have too many concurrent clients. Sometimes called a comet.

Reverse Ajax refers to the Ajax design pattern, which uses durable HTTP connections to provide low latency communications between the web server and browser. In principle, this is a way to send data from a client to a server and a mechanism for returning server data to a browser (what you need).

http://en.wikipedia.org/wiki/Reverse_Ajax

It seems like this can satisfy your needs, I just used it and it worked very well.

+2
source

how about if a hidden (or small) iframe runs a lengthy script and does javascript to check only iframe content? for example, a script writes an identifier in an iframe at its end.

0
source

Your option 2 is what I did before. Use setTimeout to limit your survey every 30 seconds or so.

0
source

ICEfaces Framework provides AJAX Push technology. They support scalable asynchronous request processing on various application servers such as Jetty, Tomcat, and Glassfish.

Although this is all Java material, it can help find the right search terms for google.

0
source

All Articles