HTTP TCP AND WEB SOCKET

Please correct me if i am wrong. One of the advantage of using HTTP protocol in web application is to minimize the share of server resources between the clients. Even if there are thousands of simultaneous connections, the load on the server is greatly reduced because of this stateless nature of HTTP.

On the other hand if the connection was statefull (eg TCP), then server would need to open and keep the connection alive for thousands requests causing a huge load on the server. So it makes a perfect sense why the HTTP was made stateless for working in web application.

My confusion is regarding the web socket, if web socket uses the TCP for real time communication between the clients an server, how can it be a good choice (considering the load on the server) for any web based real time application? How is the load for multiple connections handled by web socket server?


HTTP operations aren't necessarily lightweight or shortlived; there are many web applications which consume large amounts of resources while serving an ostensibly stateless request. Web sockets can actually be more performant than HTTP depending on the scenario - new HTTP connections, and isolated processing of the response on the server side, could be far more expensive than a long lived socket connecting the client to a server process which was able to transfer data without the overhead of new connections and data marshaling. It really depends on the type of data - the canonical websockets example is realtime chat, in which the overhead ( or latency ) of a complete web request to see new chat messages would be far heavier than a pub-sub kind of process that could multiplex new messages to a whole slew of existing websockets.

The question of whether WebSockets or "Restful" HTTP is more performant or efficient depends greatly on the scenario.


HTTP is over TCP.

Simply keeping connections open does not necessarily require a tremendous amount of resources. It does, however, usually require a different threading/IO model for handling these connections. For example, this has driven much of the nio changes in java for asynchronous and non-blocking io.

链接地址: http://www.djcxy.com/p/44818.html

上一篇: 负载均衡器是否打开了所有子服务器的套接字

下一篇: HTTP TCP和WEB SOCKET