2

I am prototyping an application using nodejs. But this question refers to hypothetical large scale roll out. What is more demanding on a server and/or bandwidth: WebSocket stay alive connections or repeated client HTTP GET requests?

For example (maybe an extreme example), is it more efficient for Twitter to allow its clients to send GET requests to its API every 20 secs, or have each client connected on an HTTP1.1 websocket? What about every 1 minute or greater, or less?

BTW, maybe it does not matter, but presuming GET requests will be handled by nginx as supposed to node, would this make a difference?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
Ross
  • 153
  • 1
  • 1
  • 6

2 Answers2

2

websockets is a better option but it isn't in all browsers yet. If you go that route you'll want to use SocketIO on the client and node.js side. That will provide a failover to flash sockets if the browser does not support websockets yet.

You gain on websockets since the data that gets sent back to the server isn't as big as a get request.

Mike
  • 21,910
  • 7
  • 55
  • 79
1

WebSockets are better because you keep connection open and don't send extra protocol headers and other stuff after each request and response. Look at this article:

During making connection with WebSocket, client and server exchange data per frame which is 2 bytes each, compared to 8 kilo bytes of http header when you do continuous polling.

yojimbo87
  • 672
  • 5
  • 10
  • 21