Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to notify my JS client without polling?

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 completed, 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 completed. 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.

like image 833
user256890 Avatar asked Mar 01 '23 09:03

user256890


1 Answers

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

like image 75
jvenema Avatar answered Mar 06 '23 18:03

jvenema