Real-time polling technology

I'm looking at the Facebook News / Ticker feed right now, and I wonder what technology / architecture it uses for asynchronous data output when any of my connections are updating. One of the possibilities I can think of is javascript setInterval for a function that aggressively polls the server for new data.

I wonder how effective this is.

Another possible technology that I can think of is something like the Comet / NodeJS architecture, which binds the client when updating on the server. I am not very familiar with this technology.

If I wanted to create something like this. What should I look at? Is the first approach the preferred way to do this? What technologies are available there that will allow me to do this?

+4
source share
3 answers

To achieve this goal, there are several technologies:

  • poll: the application makes a request every x milliseconds to check for updates
  • lengthy survey: the application makes a request to the server, but the server responds only when it has new available data (usually, if new data is not available in X seconds, an empty response is sent or the connection is killed)
  • forever frame: a hidden iframe opens on the page and a request is made for a document that relies on HTTP 1.1 chunked encoding
  • XHR streaming: allows you to send serial messages from the server without requiring a new HTTP request after each response
  • WebSockets: this is the best option, it supports connection at any time
  • Flash WebSockets: if WS is not supported by the browser, then you can enable the Flash script to improve this functionality

Typically, users use Flash WebSockets or lengthy polls when WebSockets are not available in the browser (the most efficient transport).

A great example of how to combine many transport methods and distract them is Socket.IO .

Additional resources:

http://en.wikipedia.org/wiki/Push_technology
http://en.wikipedia.org/wiki/Comet_(programming) )
http://www.leggetter.co.uk/2011/08/25/what-came-before-websockets.html
Polling a server using JavaScript
Is there a difference between long polling and using a comet
http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery
The video discusses various methods: http://vimeo.com/27771528

Even Faster Websites has a full chapter (chapter 8) on “Scaling with Comets.”

+13
source

I could be wrong, but I think Facebook relies on a “long poll” method that maintains an HTTP connection to the server for a fixed period of time. Data sent from the server launches the client side of the event, which is acting at that time. I would suggest that they use this method to support older browsers that do not have native websocket support.

I personally work on an application with similar requirements and decided to use a combination of node.js and socket.io. The socket.io module uses many polling solutions and automatically selects the best based on what is available on the client.

0
source

Perhaps you can take a look at Goliath (a non-blocking IO server written in Ruby): http://postrank-labs.github.com/goliath/

0
source

Source: https://habr.com/ru/post/1389235/


All Articles