zoukankan      html  css  js  c++  java
  • MySQL : interactive_timeout v/s wait_timeout

    Most of the database intensive applications are worring about the default values of these variables obviously. Developers used to inform me that they need to extend the wait_timeout value in order to complete the query execution.

    After some googling, it is found that default “wait_timeout” value is good enough. We may need to reduce it to boost the server performance which will helpful to minimize the “sleep” process loaded in memory. Increasing number of sleeping process will reduces the server performance gradually. So always keep the default value and make it reduce until the program/application does not create any sleeping process which would helpful to improve the performance noticeable. Slow_log_query is another possible reason to have many sleeping process.

    interactive_timeout : interactive time out for mysql shell sessions in seconds like mysqldump or mysql command line tools.
    wait_timeout” : the amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection in seconds.

    How to change the these variables

    a. changing values at run time 
    Log in to the mysql console and set the variable.

     
    mysql> SET  interactive_timeout=200;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> SET GLOBAL  interactive_timeout=200;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> show variables like "%timeout%";
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | connect_timeout            | 200  |
    | delayed_insert_timeout     | 300   |
    | innodb_lock_wait_timeout   | 50    |
    | innodb_rollback_on_timeout | OFF   |
    | interactive_timeout        | 200 |
    | net_read_timeout           | 200  |
    | net_write_timeout          | 200  |
    | slave_net_timeout          | 3600  |
    | table_lock_wait_timeout    | 50    |
    | wait_timeout               | 200 |
    +----------------------------+-------+
    10 rows in set (0.00 sec)

    b. Using my.cnf : Add the following values in /etc/my.cnf” and restart the mysql server.

     
     [mysqld]
    interactive_timeout=180
    wait_timeout=180

    Pls note that “wait_timeout” would be helpful to clear the sleeping process as “interactive_timeout” does not make any performance improvement since it affect the command line sessions. Obviously increasing the values of connect_timeoutnet_read_timeout andnet_write_timeout would help to skip the timeout errors when lengthy queries are being executed.

    How to kill the MySQL Sleeping process

     
    mysql> show full processlist;
    +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    | Id    | User       | Host                | db            | Command | Time | State | Info                  |
    +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    |  9435 | user | 192.168.10.15:52180 | db1 | Sleep   |   26 |       | NULL                  |
    |  9943 | user | localhost:51179     | db2         | Sleep   |    1 |       | NULL                  |
    |  9944 | user | localhost:54007     | db2          | Sleep   |   29 |       | NULL                  |
    |  9947 | user | localhost:60638     | db2           | Sleep   |   29 |       | NULL                  |
    | 10716 | root       | localhost           | NULL          | Sleep   | 5432 |       | NULL                  |
    | 10851 | root       | localhost           | NULL          | Query   |    0 | NULL  | show full processlist |
    +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    6 rows in set (0.00 sec)
    
    mysql> kill 9944;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> show full processlist;
    +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    | Id    | User       | Host                | db            | Command | Time | State | Info                  |
    +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    |  9435 | user | 192.168.10.15:52180 | db1 | Sleep   |    7 |       | NULL                  |
    |  9943 | user | localhost:51179     | db2         | Sleep   |    9 |       | NULL                  |
    |  9947 | user | localhost:60638     | db2         | Sleep   |   10 |       | NULL                  |
    | 10716 | root       | localhost           | NULL          | Sleep   | 5473 |       | NULL                  |
    | 10851 | root       | localhost           | NULL          | Query   |    0 | NULL  | show full processlist |
    | +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
    7 rows in set (0.01 sec)
    mysql>

    On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVEconnect option to mysql_real_connect()). 

    参考:

    http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/

    http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout

  • 相关阅读:
    c++ 文本处理
    c++ 汇编代码看内存分配
    c++ Message与Folder 拷贝 析构(没有动态空间的类)
    c++ StrVec等效vector(string)的类
    c++ istream_iterator ostream_iterator
    c++ 子类与父类之间的类型转换
    android中的空格表示
    ViewPager实现每隔两秒自动切换图片
    有关Android ListView根据项数的大小自动改变高度问题
    Android strings.xml中空格符的标识方法附xml特殊字符表示法
  • 原文地址:https://www.cnblogs.com/xiaotengyi/p/3698237.html
Copyright © 2011-2022 走看看