Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets: useful for reducing overhead?

I am building a dynamic search (updated with every keystroke): my current scheme is to, at each keystroke, send a new AJAX request to the server and get data back in JSON.

I considered opening a WebSocket for every search "session" in order to save some overhead. I know that this will save time, but the question is, is it really worth it, considering those parameters: 80ms average ping time 166ms: time between each keystroke, assuming the user types relatively fast A worst-case transfer rate of 1MB/s, with each data pack that has to be received on every keystroke being no more than 1KB. The app also takes something like 30-40ms to weld the search results to the DOM.

I found this: HTTP vs Websockets with respect to overhead, but it was a different use case.

Will websockets reduce anything besides the pure HTTP overhead? How much is the HTTP overhead (assuming no cookies and minimal headers)?

I guess that HTTP requests open a new network socket on each request, while the WebSocket allows us to use only one all the time. If my understanding is correct, what is the actual overhead of opening a new network socket?

like image 745
Ivo Avatar asked Jan 17 '12 22:01

Ivo


People also ask

What should WebSockets be used for?

The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

Are WebSockets more efficient?

If WebSockets are used, each user can both send and receive messages in real-time. WebSockets allow for a higher amount of efficiency compared to REST because they do not require the HTTP request/response overhead for each message sent and received.

How can WebSockets be better than long polling in term of performance?

WebSockets keeps a unique connection open while eliminating the latency problems that arise with long polling. Full-duplex asynchronous messaging is supported so that both the client and the server can stream messages to each other independently.

Is WebSocket better than HTTP?

All the frequently updated applications used WebSocket because it is faster than HTTP Connection. When we do not want to retain a connection for a particular amount of time or reuse the connection for transmitting data; An HTTP connection is slower than WebSockets.


1 Answers

It seems like WebSockets provide a better performance in situations like yours.

Web Socked

  • small handshake header
  • full duplex communication after the handshake.
  • After the connection is established, only 2 bytes are added per transmitted request/response

Http

  • Http headers are sent along with each request

On the other hand, WebSocket is a relatively new technology. It would be wise to investigate web browser support potential network related issues.

Ref:

http://websocket.org/quantum.html

http://www.youtube.com/watch?v=Z897fkPn7Rw

http://en.wikipedia.org/wiki/WebSocket#Browser_support

like image 114
xtrem Avatar answered Oct 21 '22 02:10

xtrem