Tomcat TCP connection results in TIME_WAIT suspended animation without excessive response optimization

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/QWERTY1994/article/details/88049119

Under Linux, use the following command to view the network connection status

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

Use the following command to view the network connection status in Windows

netstat -n |find /i "time_wait" /c

netstat -n |find /i "close_wait" /c

netstat -n |find /i "established" /c

netstat -aon|findtstr 8080

1. Modify or add TcpTimedWaitDelay       

cmd run regedit command, find HKEY_LOCAL_MACHINE / SYSTEM / CurrentControlSet / Services / TCPIP / Parameters registry subkey,

To see if there   TcpTimedWaitDelay  items, any direct modification, if not a creation and create a new REG_DWORD value named TcpTimedWaitDelay of. Set this value to decimal 30, which is a hexadecimal 0x0000001e. This value sets the wait time is 30 seconds. Stop and restart the system. Default: 0xF0, it will wait time is set to 240 seconds (4 minutes). Recommended values: the minimum value is 0x1E, it waits for the time to 30 seconds.

After the changes, reboot the system

2. Modify or add MaxUserPort

Determining available user application requests a port, TCP / IP port number can be specified from the maximum system. The default is 65535, can be transferred to 100,000.

Use regedit command access to HKEY_LOCAL_MACHINE / SYSTEM / CurrentControlSet / Services / TCPIP / Parameters registry subkey and create a new REG_DWORD value named MaxUserPort, such as set to 200,000.

 

Reference: http://www.cnblogs.com/digdeep/p/4779544.html

http://www.cnblogs.com/tianzhiliang/articles/2400176.html

 

Detailed TCP various states:

Reference: https://www.cnblogs.com/softidea/p/5741192.html

 

 

Simple explanation:

the CLOSED L : initial state, indicates a TCP connection is "closed" or "not open."

LISTEN L  : SOCKET represents a server in a listening state, you can accept the connection client.

the SYN_RCVD L  : represents the server receives a SYN message from a client requesting a connection. Under normal circumstances, this state is an intermediate state of the server-side session SOCKET three-way handshake when establishing a TCP connection process, very short, basically difficult to see with netstat this state, unless deliberately write a monitoring program, the three TCP handshake process last ACK packet will not be sent. When the TCP connection is in this state, to receive the client's ACK packet, it will enter the ESTABLISHED state.

L SYN_SENT  : This state SYN_RCVD state echoes, when the client SOCKET execution connect () to connect, it first sends a SYN packet, and then proceeds to the SYN_SENT state, and waits for transmission of three server handshake in the first two packets Wen. SYN_SENT state that the client has been sending a SYN packet.

the ESTABLISHED L  : represents the TCP connection has been successfully established.

FIN_WAIT_1 L  : The state must explain what, in fact, the true meaning of FIN_WAIT_1 and FIN_WAIT_2 two states are represented FIN messages waiting for the other side. The difference between these two states is: FIN_WAIT_1 state is actually when SOCKET in the ESTABLISHED state, it wants to take the initiative to close the connection, sends a FIN packet to each other, at which point the SOCKET into FIN_WAIT_1 state. And when the other party to respond to ACK packet, it enters the FIN_WAIT_2 state. Of course, in actual normal circumstances, regardless of whether they are in at any case, it should immediately respond to ACK packets, so FIN_WAIT_1 state is generally more difficult to see, but sometimes FIN_WAIT_2 state can still see with netstat.

L FIN_WAIT_2  : has been explained above, the origin of this state is actually SOCKET FIN_WAIT_2 state represents a half of the connection, i.e. one party call close () offered to close the connection. Note: FIN_WAIT_2 is no timeout (unlike TIME_WAIT state), this state if they do not shut down (not with the completion of four wave process), then this state will remain FIN_WAIT_2 to restart the system, more and more state FIN_WAIT_2 It will cause a kernel crash.

the TIME_WAIT L  : acknowledge the receipt of each other's FIN packet, and sends the ACK packet. TCP connections in TIME_WAIT state will wait 2 * MSL (Max Segment Lifetime, the maximum segment lifetime, refers to a TCP packet longest survival time on the Internet. Each specific TCP protocol implementations must choose a certain MSL value, RFC 1122 recommendation is 2 minutes, but the use of conventional implementations BSD 30 seconds, Linux can cat / proc / sys / net / ipv4 / tcp_fin_timeout see this value the machine), and then to return to the available state CLOSED. If the next FIN_WAIT_1 state, while the other received a packet with the FIN flag and the ACK flag, you can go directly to the TIME_WAIT state, without going through FIN_WAIT_2 state. (This should become the kind of situation that is three times or four times and waved waving)

L the CLOSING  : This state should be rare in practice, belongs to a relatively rare exception state. Normally, when one side sends a FIN packet, logically, it should first be received (or received simultaneously) each other ACK packet, stop receiving the FIN packet. But CLOSING state means the party to send FIN packets, and receives no ACK packet, but they also received each other's FIN packet. This can happen then under what circumstances? That is, when the two sides almost at the same time close () a SOCKET then, there have been both parties at the same time send a FIN packet, which is there will be CLOSING state, said both sides are being closed SOCKET connection.  

CLOSE_WAIT L  : said it is waiting to close. How to understand it? When someone close () after a SOCKET send FIN messages to yourself, your system will no doubt respond with an ACK packet to each other, then the TCP connection into CLOSE_WAIT state. Now what, you need to check whether he still has data to send to the other party, if not, then you also can close () the SOCKET and send FIN messages to each other, that is, close your connection to each other in this direction. If there are data strategy program is, it will continue to send or discarded. Simply put, when you are in CLOSE_WAIT state, it needs to be done is to wait for you to close the connection.

L LAST_ACK  : when one of the passive closed after sending a FIN packet and wait for an ACK packet, is in LAST_ACK state. Upon receipt of each other's ACK packet, you can enter into a usable state CLOSED.

 

CLOSING state:

 

 

Guess you like

Origin blog.csdn.net/QWERTY1994/article/details/88049119