Causes and solutions of Tomcat's suspended animation

When participating in the search project, I encountered the problem of tomcat suspended animation.

Situation at the time:

1. ps tomcat is running

2. Use netstat to view the 8080 connection status, there are a lot of close-wait, and some waiting for connection status

3. Check the usage of the server without excessive consumption of memory and CPU

4. Reload the interface, no error is reported, but the loading fails

5. When loading, see the tomcat log error out of memory

Check the information online, the problem is solved

Server configuration: linux+tomcat

Phenomenon: The Linux server does not crash, there are pages accessed in the browser, and there is an inaccessible situation, no 4xx or 5xx errors (feigned death) are reported, and after restarting tomcat, it returns to normal.

Reason: the default maximum number of connections (threads) of tomcat is 200, the default life cycle of each connection is 2 hours (7200 seconds), tomcat uses the http 1.1 protocol, and http1.1 defaults to long connections. After tomcat accepts and processes the request, the socket is not actively closed, so if the number of requests exceeds 200 within 2 hours, the server will experience the above suspended animation.

Solution 1: Disconnect the socket in time

Solution 2: Modify the tomcat configuration file, modify the maximum number of connections (increase)

Modify the server.xml configuration file, add the values ​​of acceptCount and maxThreads to the Connector node, and make acceptCount greater than or equal to maxThreads:

 
 

<Connector port="8080" protocol="HTTP/1.1"

 
 

            connectionTimeout="20000" 

 
 
           redirectPort="8443" acceptCount="500" maxThreads="400" />


Solution 3: Modify linux's TCP timeout (socket life cycle) limit

1
2
3
4
5
6
7
8
9
10
11
12
vi  /etc/sysctl .conf
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 30
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 1800
# 探测次数
net.ipv4.tcp_keepalive_probes=2
# 探测间隔秒数
net.ipv4.tcp_keepalive_intvl=2
 
编辑完  /etc/sysctl .conf,要重启network 才会生效
[root@temp /] # /etc/rc.d/init.d/network restart
 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325195177&siteId=291194637