wait_timeout过大造成太多sleep

安装了cacti 0.8.7b 运行几天之后,发现生成的图形断断续续。查找原因发现是mysql产生了很多sleep连接不释放,以致影响cacti的查询。
mysql> show processlist;
发现sleep很多+—-+———–+———–+——-+———+——+——-+——————+
| Id | User      | Host      | db    | Command | Time | State | Info             |
+—-+———–+———–+——-+———+——+——-+——————+
|  1 | root      | localhost | NULL  | Query   |    0 | NULL  | show processlist |
|  3 | cactiuser | localhost | cacti | Sleep   |  409 |       | NULL             |
|  4 | cactiuser | localhost | cacti | Sleep   |  403 |       | NULL             |
|  5 | cactiuser | localhost | cacti | Sleep   |  406 |       | NULL             |
| 20 | cactiuser | localhost | cacti | Sleep   |  401 |       | NULL             |
| 22 | cactiuser | localhost | cacti | Sleep   |  199 |       | NULL             |
| 23 | cactiuser | localhost | cacti | Sleep   |  179 |       | NULL             |
| 24 | cactiuser | localhost | cacti | Sleep   |  158 |       | NULL             |
| 25 | cactiuser | localhost | cacti | Sleep   |  134 |       | NULL             |
| 26 | cactiuser | localhost | cacti | Sleep   |  114 |       | NULL             |
| 41 | cactiuser | localhost | cacti | Sleep   |   90 |       | NULL             |
| 42 | cactiuser | localhost | cacti | Sleep   |   69 |       | NULL             |
| 43 | cactiuser | localhost | cacti | Sleep   |   48 |       | NULL             |
| 44 | cactiuser | localhost | cacti | Sleep   |   28 |       | NULL             |
| 45 | cactiuser | localhost | cacti | Sleep   |    4 |       | NULL             |
+—-+———–+———–+——-+———+——+——-+——————+
15 rows in set (0.00 sec)
 
mysql> show variables like ‘max_connections’;
+—————–+——-+
| Variable_name   | Value |
+—————–+——-+
| max_connections | 100   |
+—————–+——-+
1 row in set (0.00 sec)
 
mysql> show status like ‘max_used_connections’;
+———————-+——-+
| Variable_name        | Value |
+———————-+——-+
| Max_used_connections | 24    |
+———————-+——-+
1 row in set (0.00 sec)
 
mysql> show status like ‘thread%’;
+——————-+——-+
| Variable_name     | Value |
+——————-+——-+
| Threads_cached    | 0     |
| Threads_connected | 19    |
| Threads_created   | 29    |
| Threads_running   | 1     |
+——————-+——-+
4 rows in set (0.00 sec)
 
mysql> show variables like ‘wait_timeout’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| wait_timeout  | 28800 |
+—————+——-+
1 row in set (0.00 sec)
 
修改my.cnf
在[mysqld]增加如下2行:
wait_timeout = 30
interactive_timeout = 30
 
重启数据库
 
mysql> show variables like ‘wait_timeout’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| wait_timeout  | 30 |
+—————+——-+
1 row in set (0.00 sec)

猜你喜欢

转载自sundful.iteye.com/blog/1888938
今日推荐