简体   繁体   English

Netstat显示许多mysql连接的CLOSE_WAIT状态

[英]Netstat shows numerous CLOSE_WAIT states for mysql connections

The output of netstat -an shows many mysql connections in CLOSE_WAIT state and when i checked the processlist in mysql using 'SHOW PROCESSLIST' the connections shown in netstat do not appear. netstat -an的输出显示了许多处于CLOSE_WAIT状态的mysql连接,当我使用“ SHOW PROCESSLIST”检查mysql中的进程列表时,netstat中显示的连接不会出现。 What possible could be the reason for this. 这可能是其原因。 I use tomcat with mysql-connector and use a Connection Pool as well. 我将tomcat与mysql-connector一起使用,并同时使用一个连接池。

Is it that the application is not closing the mysql connection or is there any other reason for this behaviour... sometimes the CLOSE_WAIT reaches over 200. 是因为应用程序没有关闭mysql连接,还是有其他原因导致此行为...有时CLOSE_WAIT超过200。

On the application level i made sure that i close all the connections(make sure i issue a close() command in the finally block) created using jdbc. 在应用程序级别,我确保关闭所有使用jdbc创建的连接(确保在finally块中发出close()命令)。

Any help would be appreciated. 任何帮助,将不胜感激。

If the netstat is done on the application machine, it could mean misconfigured MySQL servers. 如果netstat在应用程序计算机上完成,则可能意味着MySQL服务器配置错误。

Please check following global variables in MySQL server, 请在MySQL服务器中检查以下全局变量,

  interactive_timeout
  wait_timeout

If any of these are too short, it will cause this problem. 如果其中任何一个太短,将导致此问题。 We normally set both to 1 hour when pooling is used. 当使用池时,通常将两者都设置为1小时。

The TCP is stuck in CLOSE_WAIT state when server closes connection but the connection pool hasn't got a chance to close the connection. 服务器关闭连接但连接池没有机会关闭连接时,TCP处于CLOSE_WAIT状态。

We had same issue with IIS. IIS也有同样的问题。 On windows machine we had: 在Windows机器上,我们有:

$ netstat -on | sed '1,4d' | sed 's/:/ /g' | awk '{print $6}' | sort | uniq -c

287 CLOSE_WAIT

121 ESTABLISHED

2 SYN_SENT

1 TIME_WAIT

On MySQL: 在MySQL上:

`mysql> show global variables like "interactive_timeout"; mysql显示全局变量,如“ interactive_timeout”;

interactive_timeout 28800 Interactive_timeout 28800

mysql> show global variables like "wait_timeout"; mysql>显示全局变量,如“ wait_timeout”;

wait_timeout 1440 ` wait_timeout 1440`

We change it wait_timeout=3660, will see it it will help. 我们将其更改为wait_timeout = 3660,将看到它会有所帮助。

PS: wait_timeout=1440 was done because db previosly had up to 400 of sleep connections... PS:wait_timeout = 1440已完成,因为db之前最多有400个睡眠连接...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM