`

查询数据库连接数

 
阅读更多
[6 Mar 2006 8:45] Olaf van der Spek
Description:
| Threads_connected                 | 8         |
| Threads_created                   | 6         |

How can more threads be connected than created?

How to repeat:
-[6 Mar 2006 8:51] Andrey Hristov
Hi,
do you have thread_cache set? MySQL can reuse old threads and not kill them. In this case
thread_created will be lower than threads_running.[6 Mar 2006 8:56] Olaf van der Spek
Yes, I do:
| thread_cache_size               | 5                           |

> In this case thread_created will be lower than threads_running.

I didn't mention threads_running.
But if there are currently 8 threads connected, each of those 8 threads has been created
in the past. Or are multiple connections sharing a single thread?[6 Mar 2006 9:16] Andrey Hristov
Ok, seems like a bug. My fault regarding Thread_running. Here is meaning of all these:

Thread_created -> total number of created threads (calls to pthread_create() or
equivalent)
Thread_connected -> number of connections (threads with connected user)
Thread_running -> a command is executed on a connection (thread with a connected user).[6 Mar 2006 9:34] Valeriy Kravchuk
Have you performed FLUSH STATUS?[6 Mar 2006 9:37] Olaf van der Spek
No.[6 Mar 2006 10:59] Valeriy Kravchuk
Is there any known way to repeat this result?[8 Mar 2006 19:36] Olaf van der Spek
I haven't seen it on Windows yet, but on my Linux systems I've seen it a few times.
I'll see if I can reproduce it myself.[9 Mar 2006 10:18] Valeriy Kravchuk
Please, try to repeat it. Any ideas on situations when this happens are also appreciated.[14 Mar 2006 8:59] Olaf van der Spek
I think it counts insert delayed threads as connected but not as created.[6 Apr 2006 11:03] Tomash Brechko
I can confirm the last statement of Olaf van der Spek and would also add that because of
counting insert delayed threads as connected, Threads_connected may be greater than
Max_used_connections.

In a test case below I expect both

  SHOW STATUS LIKE 'threads_connected';

to return 1:

--cut--
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

# Kill delayed_insert threads, if any.
FLUSH TABLES;

# Prerequisites.
SHOW STATUS LIKE 'delayed_insert_threads';
SHOW STATUS LIKE 'threads_connected';

# Ensure that delayed_insert_limit is not zero (FIXME: could it
# possibly be?).
SET @save_delayed_insert_limit=@@delayed_insert_limit;
SET GLOBAL delayed_insert_limit=10;

CREATE TABLE t1 (i1 INT);

# Create one delayed_insert thread.
INSERT DELAYED INTO t1 (i1) VALUES (0);

SHOW STATUS LIKE 'delayed_insert_threads';
SHOW STATUS LIKE 'threads_connected';

# Restore original setting.
SET GLOBAL delayed_insert_limit=@save_delayed_insert_limit;

DROP TABLE t1;
--cut--[6 Apr 2006 11:33] Valeriy Kravchuk
Verified just as described in the last comment with 5.0.21-BK (ChangeSet@1.1616.2144.145,
2006-04-06) on Linux:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.21

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> drop table t1;
Query OK, 0 rows affected (0.01 sec)

mysql> flush tables;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW STATUS LIKE 'delayed_insert_threads';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| Delayed_insert_threads | 0     |
+------------------------+-------+
1 row in set (0.00 sec)

Smysql> SHOW STATUS LIKE 'threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 2     |
+-------------------+-------+
1 row in set (0.00 sec)

mysql> SET GLOBAL delayed_insert_limit=10;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1(i1 int);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT DELAYED INTO t1 (i1) VALUES (0);
Query OK, 1 row affected (0.00 sec)

mysql> SHOW STATUS LIKE 'delayed_insert_threads';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| Delayed_insert_threads | 1     |
+------------------------+-------+
1 row in set (0.01 sec)

mysql> SHOW STATUS LIKE 'threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 3     |
+-------------------+-------+
1 row in set (0.00 sec)

mysql> SHOW STATUS LIKE 'threads_created';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Threads_created | 2     |
+-----------------+-------+
1 row in set (0.00 sec)

If it is intended behaviour, it should be explicitely documented.[14 Jan 2008 11:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/40983

ChangeSet@1.2583, 2008-01-14 09:28:42-02:00, davi@mysql.com +5 -0
  Bug#17954 Threads_connected > Threads_created
 
  The problem is that insert delayed threads are counted as connected
  but not as created, leading to a Threads_connected value greater then
  the Threads_created value.
 
  The solution is to increment the Threads_created variable when insert
  delayed threads are created. Nevertheless, the Threads_connected may
  still be greater then Threads_created because in reality it reflects
  the number of open connections (or open thread states) that also might
  not be associated with created threads.[22 Jan 2008 17:40] Dmitry Lenev
During the discussion of above patch the following facts were revealed:

- Currently internal 'thread_count' variable (to which 'Threads_connected' corresponds)
doesn't contains the number of currently open connections but rather a number of threads
which are handling open connections + number of some system threads (like event scheduler
and delayed insert threads, but not including replication threads).
- OTOH 'thread_created' variable reflects the number of threads which were created to
handle users connections (which is exactly what our manual says).
- Finally in 6.0 with libevent support there is no one-to-one correspondence between
connections and threads (so 'Threads_connected' reflects number of open connections
rather than number of any kind of threads).

So questions arise:
- How we should resolve discrepancy between manual and real meaning of
'Threads_connected'? Should we update the manual or change code to adhere to the manual?
Also in the former case should we include other threads like replication  threads into
this value?
- Taking into account libevent changes may be it makes sense to retire this variable and
introduce something like 'Open_connections' instead?[18 Mar 2008 0:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44161

ChangeSet@1.2604, 2008-03-17 21:55:52-03:00, davi@mysql.com +5 -0
  Bug#17954 Threads_connected > Threads_created
 
  The problem is that insert delayed threads are counted as connected
  but not as created, leading to a Threads_connected value greater then
  the Threads_created value.
 
  The solution is to increment the Threads_created variable when insert
  delayed threads are created and to change the Threads_connected variable
  to reflect (as documented in the manual) the number of client connections.[18 Mar 2008 18:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44197

ChangeSet@1.2604, 2008-03-18 15:08:06-03:00, davi@mysql.com +4 -0
  Bug#17954 Threads_connected > Threads_created
 
  The problem is that insert delayed threads are counted as connected
  but not as created, leading to a Threads_connected value greater then
  the Threads_created value.
 
  The solution is to enforce documented behavior that the
  Threads_connected value shall be the number of currently
  open connections and that Threads_created shall be the
  number of threads created to handle connections.
 
  Also there is a incompatible change that Thread_connected
  and Thread_created are not reset to 0 anymore by the FLUSH
  STATUS statement.[19 Mar 2008 12:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44218

ChangeSet@1.2604, 2008-03-19 09:03:08-03:00, davi@mysql.com +3 -0
  Bug#17954 Threads_connected > Threads_created
 
  The problem is that insert delayed threads are counted as connected
  but not as created, leading to a Threads_connected value greater then
  the Threads_created value.
 
  The solution is to enforce the documented behavior that the
  Threads_connected value shall be the number of currently
  open connections and that Threads_created shall be the
  number of threads created to handle connections.[19 Mar 2008 12:06] Davi Arnaut
Queued in 6.0-runtime[20 Apr 2008 13:01] Bugs System
Pushed into 6.0.6-alpha[21 Apr 2008 17:17] Paul DuBois
Noted in 6.0.6 changelog.

Delayed-insert threads were counted as connected but not as created,
incorrectly leading to a Threads_connected value greater than the
Threads_created value.[20 Nov 2009 20:28] Konstantin Osipov
Queued into next-mr-runtime (5.6.0)[20 Nov 2009 20:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/91167

2928 Konstantin Osipov 2009-11-20
      Backport of:
      ------------------------------------------------------------
      revno: 2572.23.1
      committer: davi@mysql.com/endora.local
      timestamp: Wed 2008-03-19 09:03:08 -0300
      message:
      Bug#17954 Threads_connected > Threads_created
     
      The problem is that insert delayed threads are counted as connected
      but not as created, leading to a Threads_connected value greater then
      the Threads_created value.
     
      The solution is to enforce the documented behavior that the
      Threads_connected value shall be the number of currently
      open connections and that Threads_created shall be the
      number of threads created to handle connections.
     @ mysql-test/r/status.result
        Add test case result for Bug#17954
     @ mysql-test/t/status.test
        Add test case for Bug#17954
     @ sql/mysqld.cc
        Change Threads_connected to reflect the number of
        open connections. SHOW_INT type variables are not
        reset.[25 Nov 2009 13:32] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091124194633-yc0achgq1ioyqzng) (version
source revid:alik@sun.com-20091124194633-yc0achgq1ioyqzng) (merge vers: 6.0.14-alpha)
(pib:13)[25 Nov 2009 13:33] Bugs System
Pushed into 5.6.0-beta (revid:alik@sun.com-20091124193905-3iyzegd75k4givuz) (version
source revid:kostja@sun.com-20091120203000-lky3jqo7r35s24ps) (merge vers: 5.6.0-beta)
(pib:13)[25 Nov 2009 14:44] Paul DuBois
Noted in 5.6.0 changelog.

Already fixed in 6.0.x.[6 Mar 2010 11:03] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source
revid:vvaintroub@mysql.com-20091125142014-7asc9sj33gzki0ym) (merge vers: 5.6.0-beta)
(pib:16)
分享到:
评论

相关推荐

    如何查看sql server数据库连接数

    2. 在下面的项目中选择用户连接(User Connection),这样就可以实时查询到 SQL Server 数据库连接数。 方法二:通过系统表查询 可以通过系统表来查询 SQL Server 数据库连接数。具体步骤如下: 1. 使用以下查询...

    更改数据库连接数

    数据库连接数调整 在本篇文章中,我们将讨论如何调整数据库连接数,以解决系统不能登陆的问题。在系统中,数据库连接数是一个非常重要的参数,因为它直接影响着系统的性能和可扩展性。当数据库连接数不够时,可能会...

    数据库连接数查看工具

    查看数据库连接数,直接放到tomcat服务器下用浏览器访问即可

    数据库连接池查询

    #### 二、数据库连接数过多的问题及解决方案 当系统中存在大量的数据库连接请求时,可能会导致连接数过多的情况发生。这种情况不仅会消耗大量的服务器资源,还可能导致数据库性能下降甚至出现连接失败等问题。因此...

    修改Oracle数据库连接数

    数据库连接数是指数据库允许同时建立的最大会话数,包括用户进程和服务器进程的数量。在Oracle数据库中,这个参数通常是用“processes”来表示。默认情况下,Oracle数据库的连接数可能只配置了几十个,这对于生产...

    数据库连接池技术详解

    某一应用最大可用数据库连接数的限制,避免某一应用独占所有数据库资源。 在较为完备的数据库连接池实现中,可根据预先的连接占用超时设定,强制收回被占用连接。从而避免了常规数据库连接操作中可能出现的资源泄漏 ...

    修改数据库最大连接数以及linux系统下ORACLE数据库启动多实例参照.pdf

    数据库最大连接数修改与 Oracle 多实例启动在 Linux 系统下 一、修改 Oracle 数据库允许的最大连接数 Oracle 数据库的最大连接数可以通过修改参数文件或使用 alter system 语句来实现。下面是修改最大连接数的步骤...

    数据库的连接数和连接池

    "数据库连接数和连接池" 数据库连接数是指系统中可以同时存在的连接数量,而连接池则是为了解决频繁的数据库连接创建和销毁问题的技术。下面我们来详细了解这两个概念。 数据库连接数的限制: 在了解数据库连接数...

    多线程下mysql连接数过多解决demo

    这通常是由于每个线程创建一个独立的数据库连接导致的,当并发线程数量增加时,连接池中的连接数量也随之增加,如果超过服务器允许的最大连接数,就可能导致应用程序无法正常工作,甚至引发“Too many connections”...

    Oracle与MySQL在数据库连接数限制上的比较分析

    数据库连接数限制是数据库性能调优中的一个重要方面。Oracle和MySQL作为两个主流的关系数据库管理系统,在连接数限制上有着不同的处理机制和配置方法。本文将探讨Oracle和MySQL在数据库连接数限制上的差异,并提供...

    常用jdbc数据库连接jar包,数据库连接池jar包

    例如,你需要确保JDBC驱动版本与数据库服务器版本兼容,合理设置连接池的参数,如最小连接数、最大连接数、超时时间等,以平衡资源利用率和响应速度。 总的来说,这个资源集合对于Java开发者尤其是后端开发人员来说...

    C#高效数据库连接池源码

    - **最小/最大连接数**:设置合适的最小和最大连接数,平衡资源使用和性能需求。 - **连接检测**:定期检查连接有效性,防止因网络或其他问题导致的死连接。 - **连接重用策略**:根据连接的使用频率和状态决定...

    查看oracle数据库的连接数以及用户、数据库锁定进程

    使用以下SQL命令可以查询Oracle数据库中的总连接数: ```sql SELECT COUNT(*) FROM v$session; ``` 这条语句返回的结果即为当前数据库的所有会话数量。 2. **查询并发连接数** 要获取当前正在活跃的会话数量...

    C# 数据库连接池 C# 数据库连接池

    2. **适当设置连接池大小**:根据应用的并发用户量和数据库负载,合理设置最小和最大连接数。 3. **及时关闭事务**:长时间未结束的事务会占用连接池中的连接,导致其他请求无法获取连接。 4. **避免长时运行查询*...

    Java 数据库连接泄漏 解决方法

    2. **配置最大数据连接数量**(可选):虽然这不是必须的步骤,但适当调整最大连接数可以帮助防止过多的连接同时打开。 3. **连接泄漏自动关闭**:启用连接泄漏自动关闭功能,可以通过设置“非活动连接超时”属性来...

    Java jdbc数据库连接池总结

    我们可以通过设定连接池最大连接数来防止系统无尽的与数据库连接。更为重要的是我们可以通过连接池的管理机制监视数据库的连接数量、使用情况,为系统开发、测试及性能调整提供依据。 连接池的基本工作原理是:当...

    易语言使用数据库连接组件打开EXCEL

    在IT领域,数据库连接组件是用于程序与数据库交互的关键工具,而易语言作为一种中文编程语言,为开发者提供了简便的方式来操作数据库。本篇文章将详细讲解如何使用易语言的数据库连接组件来打开并操作Excel文件。 ...

    oracle连接数问题

    然而,随着业务量的增加,Oracle数据库可能会遇到连接数的问题,这往往与内存限制紧密相关。本文将深入探讨如何通过修改Oracle参数来解决这一问题,确保数据库能够稳定运行并满足高并发需求。 ### Oracle连接数问题...

Global site tag (gtag.js) - Google Analytics