HTTP/2 or Websockets for low latency client to server messages

前端 未结 3 1307
臣服心动
臣服心动 2021-01-02 01:28

I have a requirement to have very low latency for client to server messages in my web application.

I have seen several posts on stackoverflow saying it would be pref

3条回答
  •  感动是毒
    2021-01-02 01:41

    It will depend on your client and your requirements. If you are sure that your client won't close the underlying TLS connection of HTTP/2 (even when unutilized for some time), the latency for sending out message/request might be similar to a persisted websocket connection. If the client closes the connection after some idle time and a new TLS connection needs to be established, it will be worse.

    In the case of a browser as client, you know that the web socket connection will be persistent, and don't know anything about HTTP connections. Maybe you can force the browser to keep up the connection by making a dummy request to a SSE endpoint on the same server and keep that up, but it's a bit of a workaround.

    Apart from connection establishment there a different kinds of overheads on both protocols (flow-control & stream headers vs masking), and the impact can most likely only be estimated based on the actual application needs.

提交回复
热议问题