0

我有使用 mysql 数据库和 mysql .net 连接器的 asp.net mvc 3 应用程序。应用程序使用成员资格、角色、配置文件提供者和 subsonic3 作为数据层。应用程序能够浪费非常多的连接,最终它会因超时异常而崩溃。我克隆了服务器/应用程序设置,并设法重现了 10 个连接限制的问题。我现在拥有的信息如下。首先,innoDb 事务状态中的“清理”是什么意思?我找到了这个信息:http ://dev.mysql.com/doc/refman/5.0/en/general-thread-states.html但我看不到交易如何保持这种状态。当然,我迫切需要任何可以提供帮助的信息。我实际上调试了 Subsonic 代码,我没有看到它做错了什么。当我变得更加绝望时,我想我会再做一次。现在我想看看连接器中发生了什么。下面列出的连接是浪费的,即不可重复使用。连接:

mysql> SHOW FULL PROCESSLIST;
+----+------+-----------------+------------+---------+------+-------+-----------------------+
| Id | User | Host            | db         | Command | Time | State | Info                  |
+----+------+-----------------+------------+---------+------+-------+-----------------------+
|  2 | root | localhost:49167 | NULL       | Query   |    0 | init  | SHOW FULL PROCESSLIST |
| 15 | root | localhost:49360 | somedbname | Sleep   |  260 |       | NULL                  |
| 16 | root | localhost:49361 | NULL       | Sleep   |  260 |       | NULL                  |
| 19 | root | localhost:49437 | somedbname | Sleep   | 3969 |       | NULL                  |
| 20 | root | localhost:49439 | somedbname | Sleep   | 3702 |       | NULL                  |
| 21 | root | localhost:49440 | somedbname | Sleep   | 3396 |       | NULL                  |
| 22 | root | localhost:49457 | somedbname | Sleep   | 3102 |       | NULL                  |
| 23 | root | localhost:49460 | somedbname | Sleep   | 2802 |       | NULL                  |
| 24 | root | localhost:49478 | somedbname | Sleep   | 1929 |       | NULL                  |
| 26 | root | localhost:49497 | somedbname | Sleep   | 1629 |       | NULL                  |
| 27 | root | localhost:49498 | somedbname | Sleep   | 1329 |       | NULL                  |
+----+------+-----------------+------------+---------+------+-------+-----------------------+
11 rows in set (0.00 sec)

InnoDb 状态:

=====================================
2013-02-13 07:54:01 790 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 46 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 311 srv_active, 0 srv_shutdown, 14316 srv_idle
srv_master_thread log flush and writes: 14623
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 300
OS WAIT ARRAY INFO: signal count 296
Mutex spin waits 207, rounds 6140, OS waits 111
RW-shared spins 200, rounds 6000, OS waits 172
RW-excl spins 1, rounds 480, OS waits 15
Spin rounds per wait: 29.66 mutex, 30.00 RW-shared, 480.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 7160
Purge done for trx's n:o < 7157 undo n:o < 0 state: running but idle
History list length 650
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 7159, not started
MySQL thread id 27, OS thread handle 0xb6c, query id 11259 localhost ::1 root cleaning up
---TRANSACTION 7124, not started
MySQL thread id 26, OS thread handle 0xc88, query id 11080 localhost ::1 root cleaning up
---TRANSACTION 0, not started
MySQL thread id 2, OS thread handle 0x790, query id 11270 localhost ::1 root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 7005, not started
MySQL thread id 24, OS thread handle 0xde0, query id 10510 localhost ::1 root cleaning up
---TRANSACTION 6865, not started
MySQL thread id 23, OS thread handle 0x1d0, query id 9615 localhost ::1 root cleaning up
---TRANSACTION 6697, not started
MySQL thread id 22, OS thread handle 0x874, query id 8824 localhost ::1 root cleaning up
---TRANSACTION 6647, not started
MySQL thread id 21, OS thread handle 0xfa8, query id 8546 localhost ::1 root cleaning up
---TRANSACTION 6531, not started
MySQL thread id 20, OS thread handle 0x910, query id 8019 localhost ::1 root cleaning up
---TRANSACTION 6243, not started
MySQL thread id 19, OS thread handle 0x740, query id 6886 localhost ::1 root cleaning up
---TRANSACTION 0, not started
MySQL thread id 15, OS thread handle 0x75c, query id 11268 localhost 127.0.0.1 root cleaning up
--------
FILE I/O
--------
I/O thread 0 state: wait Windows aio (insert buffer thread)
I/O thread 1 state: wait Windows aio (log thread)
I/O thread 2 state: wait Windows aio (read thread)
I/O thread 3 state: wait Windows aio (read thread)
I/O thread 4 state: wait Windows aio (read thread)
I/O thread 5 state: wait Windows aio (read thread)
I/O thread 6 state: wait Windows aio (write thread)
I/O thread 7 state: wait Windows aio (write thread)
I/O thread 8 state: wait Windows aio (write thread)
I/O thread 9 state: wait Windows aio (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
1017 OS file reads, 3059 OS file writes, 2067 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
 insert 0, delete mark 0, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 17393, node heap has 1 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 2556460
Log flushed up to   2556460
Pages flushed up to 2556460
Last checkpoint at  2556460
0 pending log writes, 0 pending chkp writes
852 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 8585216; in additional pool allocated 0
Dictionary memory allocated 142202
Buffer pool size   512
Free buffers       255
Database pages     256
Old database pages 0
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0 single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 988, created 63, written 1772
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 256, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Main thread id 1240, state: sleeping
Number of rows inserted 49, updated 955, deleted 0, read 5238
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

Web 应用程序被以下异常卡住并且在应用程序池被回收之前无法使用。

System.Configuration.Provider.ProviderException: An exception occurred. 
Please check the Event Log. ---> MySql.Data.MySqlClient.MySqlException: 
error connecting: Timeout expired.  
The timeout period elapsed prior to obtaining a connection from the pool.  
This may have occurred because all pooled connections were in use and max 
pool size was reached.
4

1 回答 1

0

好的,我将提供一些可以在类似情况下重复使用的调试步骤,以给自己洗点。

我确实升级到了 Version=6.6.5.0。我下载了源代码并将调试器附加到连接器,并且池工作正常,但我仍然遇到同样的问题。来自池的连接未被重用。

我将手表添加到私有 MySqlPool.inUsePool;并看到所有卡住的连接都在那里使用。通过添加另一个手表(实际上是其中的 10 个):inUsePool[0-10].reader.Command.CommandText 帮助我识别代码中没有关闭阅读器/连接的部分。所有卡住的连接确实被我的读者占用了。都有相同的 SQL 命令文本,在应用程序中只调用一次。

于 2013-02-15T10:15:03.130 回答