Socket Communications exploration (two) -socket cluster

  In the previous section we have " the Socket Communications to explore (a) " How to implement a tcp connection, but this is just one of the most junior BIO achieve, and did not add a thread pool, the practical application is rarely used in this way, because he had to consider when a large number of Tcp connection is established, the server how safe and stable operation? why?

  1, BIO implementation, is a blocking (on a rearmost implementations Although there is no data, it does not clog);

  2, for each server have opened up a thread for processing connection, and in the case of disconnecting the connection, the thread will not be released;

  Based on the above, there is a time when a large number of connection establishment, the server will open up a lot of threading and not released, and the thread will occupy system resources, which would cause the system to run out of resources, there is no system resource connection request will be waiting to be processed, or even more immediate crash program, the most direct way is to add a thread pool to prevent crashes, a lot of processing connection is also required him to think of other methods.

  We all know that when faced with a large number of web application request, we will be deployed such as cluster or distributed the same token, we can also be deployed for multiple socket server.

  In general, since Tcp connection client needs to know the server's IP with the port, then this means that the client needs to know the address and port all of the target server, so if there is a host on our server dedicated to load balancing and then select the port with load balancing to complete the address is returned to the client, and the client then initiates a real connection requests. FIG particular request as follows (Refer to: https://wenku.baidu.com/view/d5769f85d4d8d15abe234e7c ):

  

  The figures above is actually a virtual server with the server load balancing, it will give priority to all clients connect to the server to obtain a real server connected (real server); the particular model of communication process is as follows:

    ①client the SYN packet is listening to VS;

    ②VS according to a scheduling policy to select RS, RS to the SYN packet;

    VS SYN requests ④RS response, SYN ACK packet back to the VS;

    ④VS the received SYN ACK packet to the Client;

    5 ④client the last ACK handshake packet directly to the RS, this time into the client has established a connection state, RS after receiving the ACK packet has entered the connected state has been established

    ⑥client direct communication and RS, independent of the process VS.

  Through the above model to complete the TCP server cluster deployment, the specific implementation process, not within the scope of Benpian, for the present, I only know that one implementation, if there are other programs, we can mutually communicate with……

  

Guess you like

Origin www.cnblogs.com/onedayinMay/p/12203618.html