Some sites will be running for some time after the server down, there are many reasons for this phenomenon: such as the Tomcat heap and non-heap memory settings, the program failed to release memory space caused by memory overflow, or some process has been running failed to release, resulting in a large amount of CPU consumption.
But in addition to the program itself, there may be customer service side access caused (of course, the client also contains such as Spider software Search engine), if the server and the client to establish a long link (you can use the "netstat-a" command to view network access information), This requires a certain set of connection for HTTP response headers.
The introduction is as follows:
1. Explain:
A Connection header field may appear in both the request and Reponse headers in http1.1, which means how to handle long links when client and server communicate.
In http1.1, both client and server are the default support long links. If the client uses the HTTP1.1 protocol, but does not want to use a long link, you need to indicate in the header that the connection value is close, and if the server does not want to support long links, you also need to specify in response that the connection value is close .
Whether the header for request or response contains a connection with a value of close, the TCP link that is currently in use is broken after the request has been processed. You must create a new TCP link later when the client makes a new request. The close setting of the HTTP connection allows either side of the client or the server to shut down the underlying connection both requiring that the TCP connection be turned off after the request is processed.
2. How to set up in a program:
Can be added in the filter: Response.setheader ("Connection", "close");
related to: Solve the server to create a large number of close_wait problems
To solve this problem, you can modify the system's parameters (/etc/sysctl.conf file), the system default timeout time is 7,200 seconds, that is 2 hours.
The defaults are as follows:
Tcp_keepalive_time = 7200 seconds (2 hours)
Tcp_keepalive_probes = 9
TCP_KEEPALIVE_INTVL = Seconds
This means that if a TCP connection is idle 2 hours later, the kernel does not initiate probe. If probe 9 times (75 seconds) is unsuccessful, the kernel abandons it completely and considers the connection to be invalid
After modification
Sysctl-w net.ipv4.tcp_keepalive_time=30
Sysctl-w net.ipv4.tcp_keepalive_probes=2
Sysctl-w net.ipv4.tcp_keepalive_intvl=2
After this modification, the server reclaims TCP connections that are not closed in a short time.