开发者

Netstat shows numerous CLOSE_WAIT states for mysql connections

开发者 https://www.devze.com 2022-12-31 22:49 出处:网络
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. What p

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. What possible 开发者_运维问答could be the reason for this. I use tomcat with mysql-connector and use a Connection Pool as well.

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.

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.

Any help would be appreciated.


If the netstat is done on the application machine, it could mean misconfigured MySQL servers.

Please check following global variables in MySQL server,

  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.

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.


We had same issue with IIS. On windows machine we had:

$ 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> show global variables like "interactive_timeout";

interactive_timeout 28800

mysql> show global variables like "wait_timeout";

wait_timeout 1440 `

We change it wait_timeout=3660, will see it it will help.

PS: wait_timeout=1440 was done because db previosly had up to 400 of sleep connections...

0

精彩评论

暂无评论...
验证码 换一张
取 消