TIME_ Wait and close_ WAIT

First look at the state changes of three handshakes and four waves:

There are usually two situations:

Because Linux allocates limited file handles to a user, and time_ Wait and close_ If the two wait states are maintained all the time, it means that the corresponding number of channels are occupied all the time, and "occupy the pit without effort". Once the maximum number of handles is reached, new requests cannot be processed, followed by a large number of toomany open files exceptions.

About time_ WAIT

This situation is quite common. This problem is often encountered on some crawler servers or web servers (if the NMS does not optimize the kernel parameters during installation). How does this problem occur?

As can be seen from the diagram above, time_ Wait is the state maintained by the party actively closing the connection. For the crawler server, it is a "client". After completing a crawling task, it will initiate actively closing the connection and enter time_ Wait state, and then completely turn off recycling after maintaining this state for 2msl (max segment lifetime). Why do you do this? Obviously, the connection has been actively closed. Why do you want to keep resources for a period of time? This is specified by the designer of TCP / IP, mainly for the following considerations:

The solution is to enable the server to quickly recycle and reuse those times_ Wait resources.

In the above parameters:

About close_ WAIT

If you keep it closed_ In the wait state, there is only one case, that is, after the other party closes the connection, the server program itself does not send further ack signals. In other words, after the other party's connection is closed, the program does not detect it, or the program forgets to close the connection at this time, so this resource has been occupied by the program. In this case, there is no way to modify the server kernel parameters. The server has no right to actively recover the resources occupied by the program unless the program is terminated.

Give an example to illustrate close_ How wait happens: server a is a crawler server. It uses a simple httpclient to request Apache on resource server B to obtain file resources. Normally, if the request is successful, server a will actively send a request to close the connection after grabbing the resources. At this time, it will actively close the connection, We can see that the connection status of server a is time_ WAIT。 What if an exception occurs? Assuming that the requested resource does not exist on server B, server B will send a request to close the connection at this time. Server a passively closes the connection. If the programmer forgets to let httpclient release the connection after server a passively closes the connection, it will cause close_ Wait status.

Once you encounter a large number of close_ Wait, there is only one solution: check the code.

##########################

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>