最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - How to notify my JS client without polling? - Stack Overflow

programmeradmin3浏览0评论

Context: From my javascript web UI, I launch a long-running (several minutes) operation that is conducted on the .NET2.0 backend. The call returns immediately with operation ID while the long-running operation run parallel. The operations are not CPU intensive, but conduct slow network calls. Once the operation is pleted, I want to see the results in the web UI.

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

Options I have considered:

Option 1: I launch the long-running operation asynchronously directly from JS and I expect the return value to be the endresult instead of an operation ID. 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 lock up for several minutes. You do not need too many long-running parallel requests to cause the ThreadPool to starve and bring the entire server to it knees even if there is sufficient processing power.

Option 2: With the operation ID, I start to poll the server if the operation is pleted. However, this is a denial of service attack against my own server. Furthermore, there must be fair ajax solution to it. This is not a unique problem.

Context: From my javascript web UI, I launch a long-running (several minutes) operation that is conducted on the .NET2.0 backend. The call returns immediately with operation ID while the long-running operation run parallel. The operations are not CPU intensive, but conduct slow network calls. Once the operation is pleted, I want to see the results in the web UI.

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

Options I have considered:

Option 1: I launch the long-running operation asynchronously directly from JS and I expect the return value to be the endresult instead of an operation ID. 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 lock up for several minutes. You do not need too many long-running parallel requests to cause the ThreadPool to starve and bring the entire server to it knees even if there is sufficient processing power.

Option 2: With the operation ID, I start to poll the server if the operation is pleted. However, this is a denial of service attack against my own server. Furthermore, there must be fair ajax solution to it. This is not a unique problem.

Share Improve this question asked Aug 26, 2009 at 10:55 user256890user256890 3,4245 gold badges29 silver badges45 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 3

Check out WebSync, a et implementation for .NET. Should be exactly what you're looking for.

Polling, if done properly, will not have a noticeable effect on your server load. You should customize the interval to best cover the specifics of your server job - e.g. you don't poll the server for at least 2 minutes if you know that the operation usually takes longer. Even after that you choose a big enough interval - e.g. 10 sec. Using a web service request or a custom handler will minimize the traffic and the server time needed to process the request.

Perhaps reverse ajax is useful if you wont have too many concurrent clients. This is sometimes called et.

Reverse Ajax refers to an Ajax design pattern that uses long-lived HTTP connections to enable low-latency munication between a web server and a browser. Basically it is a way of sending data from client to server and a mechanism for pushing server data back to the browser(what you need).

http://en.wikipedia/wiki/Reverse_Ajax

Sounds like it might suit your needs, i just used it and it worked really well.

what about having hidden (or small) iframe run the long-running script and making javascript to check only the content of the iframe? e.g. script writes ID to the iframe on its end.

Your option 2 is exactly what I've done before. Use setTimeout to limit your polling to every 30 seconds or so.

The ICEfaces Framework provides an AJAX Push technology. They support Scalable Asynchronous Request Processing on various application servers like Jetty, Tomcat and Glassfish.

While this is all Java stuff, it might help finding the right search terms for google.

发布评论

评论列表(0)

  1. 暂无评论