Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long polling for real time messages/updates

What is a good strategy for implementing long polling in a .Net application.

Would it mean having a JS setInterval() based approach to keep polling the server for updates that can be rendered on the page. I have always thought that that could be a challenge when it comes to scalability as it seems it would generate a lot of extra requests to the web server. I have read that this type of functionality should be implemented using a non blocking web server (single threaded) NODE.js etc... Since there's only one thread/event loop it seems like the requests would have to be very lightweight to service several requests in a timely fashion. Can Node.Js trigger db calls?

I have seen an online dating site where you receive notification in the form of a fad-in/fade-out popup when someone visits your profile when you're currently logged into the system. I am impressed that something like that can work so well for a high volume site.

Is it reasonable to assume that this type of notification system is implemented using long polling? Based on constantly polling through JS?

I am seeing similar behind the scenes updates her on the SO site as well (messages/votes etc) Does this use a similar strategy as well?

like image 888
TGH Avatar asked Mar 31 '12 06:03

TGH


People also ask

What is long polling used for?

HTTP Long Polling is a technique used to push information to a client as soon as possible on the server. As a result, the server does not have to wait for the client to send a request. In Long Polling, the server does not close the connection once it receives a request from the client.

What does long polling mean?

Overview. Long polling is a method that server applications use to hold a client connection until information becomes available. This is often used when a server must call a downstream service to get information and await a result.

Why do we want to use long polling instead of WebSocket then?

Long Polling is Half-Duplex meaning that a new request-response cycle is required each time the client wants to communicate something to the server. Long Polling usually produces slightly higher average latency and significantly higher latency variability than WebSockets.

How is long polling implemented?

The Client sends an HTTP request and then waits for a response. When an update is available, the server provides the Client a complete response. After getting a response, the Client typically sends a new long-poll request, either immediately or after a pause, to allow for an appropriate latency duration.


2 Answers

SignalR and pokein are two good options.

A blog post by scott hanselman which explains using SignalR http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx

like image 194
ZeNo Avatar answered Sep 29 '22 02:09

ZeNo


Realtime web applications have been with us for quite some time now: the history of Polling goes from setInterval Technique to HTML5 WebSockets.

Here you can find Simple Long Polling Example with JavaScript.

http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

like image 21
antonjs Avatar answered Sep 29 '22 04:09

antonjs