Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "long polling" the most efficient way to create a Web Real Time App?

I want to create an application like this:

http://collabedit.com/

What is the most efficient way to create this real time application?

Flash? Long polling? Http Streaming? or something else?

Thanks ;)

like image 659
xRobot Avatar asked Mar 13 '10 21:03

xRobot


People also ask

When should I use long polling?

Long polling takes HTTP request/response polling and makes it more efficient, since repeated requests to a server wastes resources. For example, establishing a new connection, parsing the HTTP headers, a query for new data, response generation and delivery, and finally connection closure and clean up.

What is long polling and why would it be beneficial to use?

Long polling is the simplest way of having persistent connection with server, that doesn't use any specific protocol like WebSocket or Server Side Events. Being very easy to implement, it's also good enough in a lot of cases.

Is long polling scalable?

This model can be seen as a server-side local-polling model. Kafka is an example of technology implementing long polling model, and that's the reason why it is more scalable compared with RabbitMQ when there is a massive amount of messages and clients.

What is the difference between long polling and short polling?

In simple terms, Short polling is an AJAX-based timer that calls at fixed delays whereas Long polling is based on Comet (i.e server will send data to the client when the server event happens with no delay). Both have pros and cons and suited based on the use case.


3 Answers

For now, long polling is probably the best solution. Many big-name sites have long polling implementations, including Facebook, Google and eBay. Not everyone has Flash installed/enabled in their browsers. In the future Web Sockets might be able to do an easier job of it for us.

Update: As of this writing, the WebSocket API is implemented in the latest WebKit (Chrome/Safari) and Firefox 4 beta. There is also a public snapshot build of Opera available for download with an implementation of the API. This means testing the API is widely available. For more information, see this answer.

like image 121
Andy E Avatar answered Nov 15 '22 18:11

Andy E


All the different methods have different pros and cons, I'm not an specialist on the differences, that's why I'll recomend you to avoid making the choice, avoid the development and tuning that each approach involves, avoid the future changes in available technologies (ie. as HTML5 web sockets arrival), using a library that abstracts the transport method used, and chooses the best approach based on client capabilities:

http://socket.io/

this wonderful library makes creating realtime apps amazingly simple! and there are various server-side implementations: Python (Tornado), Java, Google GO, Rack (Ruby), besides the mainstream implementation in Node.js (server-side JavaScript)

like image 21
Benja Avatar answered Nov 15 '22 17:11

Benja


I don't think long-polling is most efficient way to do Comet. Anyway, it sends new HTTP request after response is got. It cost more extra HTTP requests than HTTP streaming.

But, long-polling might be more reliable and easier to implement than HTTP streaming. According to this article in Google Code, HTTP streaming might not be functional if intermediate HTTP proxy buffers content.

It is interesting that GMail doesn't use long-polling. With the help of Http sniffer, it is clear that it uses HTTP streaming for Comet.

like image 38
Morgan Cheng Avatar answered Nov 15 '22 16:11

Morgan Cheng