Advantages and disadvantages of long and short connections

Advantages and disadvantages of long and short connections

It can be seen from the above that long connections can save more TCP establishment and closing operations, reduce waste, and save time. Long connections are suitable for clients that frequently request resources. In the application scenario of a long connection, the client side generally does not actively close the connection. When the connection between the client and the server is not closed, as the client connection increases, the server will maintain too many connections. At this time, the server needs to adopt some strategies, such as closing some connections that have not been requested for a long time, which can prevent some malicious connections from causing damage to the server-side service; if conditions permit, you can limit the maximum number of long connections for each client. Completely avoid malicious clients from dragging down the overall back-end service.

The management of short connections is relatively simple for the server, and the existing connections are all useful connections and do not require additional control means. However, if the client requests frequently, more time and bandwidth will be wasted on TCP establishment and closing operations.

The generation of long connections and short connections depends on the shutdown strategy adopted by the client and server. Different application scenarios are suitable for different strategies.

As can be seen from the above, the long connection may be omitted to establish and operate more TCP off, reduce waste and save time . For customers who frequently request resources, long connections are more suitable. But here there is a problem , the survival function of the probing cycle is too long , there is just detect it alive TCP connections, it is more gentle approach, encountered a malicious connections, keep-alive function is not enough to make up. In the application scenario of a long connection, the client generally does not actively close the connection between them. If the connection between the Client and the server is not closed, there will be a problem. As more and more client connections, the server Sooner or later, when you can’t handle it , the server side needs to adopt some strategies, such as closing some connections that have not been read or written for a long time, so as to avoid some malicious connections that cause damage to the server side services; if conditions allow, you can The client machine is granular, limiting the maximum number of long connections for each client, which can completely avoid a painful client from influencing the back-end service.

The management of short connections is relatively simple for the server, and the existing connections are all useful connections and do not require additional control means. However, if the client requests frequently , time and bandwidth will be wasted in TCP establishment and closing operations .

The generation of long and short connections lies in the closing strategy adopted by the client and server. Specific strategies are adopted for specific application scenarios. There is no perfect choice, only a suitable choice.

Long connection short connection operation process

Guess you like

Origin blog.csdn.net/qq_34462698/article/details/108601442