为什么 max_used_connections 状态在达到 max_connections 后不会自动刷新,即使 Threads_connected 下降

Gop*_*ath 8 mysql performance max-connections mysql-5.1 performance-testing

我一直在想,max_used_connections一旦达到 的峰值,为什么值不会下降max_connections

我总是刷新状态并降低此值以避免数据库连接拒绝错误和错误日志中的警告消息:

=====
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
121112 14:04:36 [Warning] Too many connections
=======
Run Code Online (Sandbox Code Playgroud)
mysql> select version();show variables like "%max_connections%";show global status 
         like "%Max_used%";show status like "%thread%";
            +--------------+
            | version()    |
            +--------------+
            | 5.1.52-2-log |
            +--------------+
            1 row in set (0.00 sec)

            +-----------------+-------+
            | Variable_name   | Value |
            +-----------------+-------+
            | max_connections | 150   |
            +-----------------+-------+
             1 row in set (0.00 sec)

            +----------------------+-------+
            | Variable_name        | Value |
            +----------------------+-------+
            | Max_used_connections | 151   |
            +----------------------+-------+
            1 row in set (0.00 sec)

            +----------------------------+-------+
            | Variable_name              | Value |
            +----------------------------+-------+
            | Com_show_thread_statistics | 0     |
            | Delayed_insert_threads     | 0     |
            | Slow_launch_threads        | 0     |
            | Threads_cached             | 89    |
            | Threads_connected          | 2     |
            | Threads_created            | 1344  |
            | Threads_running            | 2     |
            +----------------------------+-------+
            7 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
mysql> show variables like "%thread_cache%";
            +-------------------+-------+
            | Variable_name     | Value |
            +-------------------+-------+
            | thread_cache_size | 90    |
            +-------------------+-------+
            1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

这是中止的连接状态:

mysql> show global status like "%Aborted%";
            +------------------+----------+
            | Variable_name    | Value    |
            +------------------+----------+
            | Aborted_clients  | 119      |
            | Aborted_connects | 43855304 |
            +------------------+----------+
            2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
  1. 我在某些情况下观察到max_used_connections,一旦threads_connected下降,该值就会动态下降。

  2. 这只是增加 的指示变量max_connections吗?发布此查询以更好地理解。请问有详细的解释吗?

我在某处读到thread_cache_size应该大于max_connections,如果小于会有什么影响?

Max_used_connections

自服务器启动以来同时使用的最大连接数。

Mic*_*bot 10

它不会下降,因为它不应该下降。

Max_used_connections是一个状态变量,定义为“自服务器启动以来同时使用最大连接数”。

事实证明,您还可以使用 将值重置为当前连接数FLUSH STATUS

但这不是任何事情的“部分解决方案”,因为它不会改变任何事情。您正在完成的唯一的事情FLUSH STATUS就是基线的唯一信息,状态变量的值排序的:重置你看,下降到目前的值值状态变量Threads_connected-连接的当前数量。

此操作不会更改有关服务器行为的任何内容。如果您在这样做后发现行为发生了变化,那是巧合。

mysql> SHOW STATUS LIKE 'Threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 225   |
+-------------------+-------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

以上将是您在进行故障排除时观看的更有用的价值。它显示当前计数。

但解决您的问题,您可能已不正确地释放其连接的应用程序-这需要在别处固定的,不能在MySQL中-或者你可能是正确的-你需要增加值max_connections全局变量-在考虑C.5.2.7 Too many connections 中写的内容之后。该页面还解释了为什么上面的输出显示Max_used_connections151 而不是max_connections150。

thread_cache_size值设置为大于max_connections似乎是非常无用的建议......缓存不可能增长得比max_connections任何地方接近该大小的缓存都大,只有当你的线程有大量流失时才有意义......在表现良好的应用程序中,情况并非如此。