c3p0明显死锁

h5qlskok  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(382)

我的服务器曾经看到 APPARENT DEADLOCK 在日志里。我有几个服务器在负载均衡器后面运行,有趣的是我看到死锁同时发生在所有服务器上(有人知道它为什么会影响所有服务器吗)?。在此期间,通常需要200毫秒的mysql查询需要>60秒。下面是日志的样子:

com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@58780f76
 -- APPARENT DEADLOCK!!! Complete Status: 
        Managed Threads: 3
        Active Threads: 3
        Active Tasks: 
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@25ff87d4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@10ccf7ef (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@3305ec37 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
        Pending Tasks: 
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@39cc9e5a
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@60d46f90
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@17509fea
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@b28bd63
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@56cbdc12
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@15a091b4
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@61ce325
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@48119520
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@4032fb7c
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@518eefff
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@30ea3b20
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@74960088
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@23a8fc7d
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@5ff0ee0
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@642d0644
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@207bc809
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@44d4936f
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@39a10d1b
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@3532334d
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@4bf79e62
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@2bd83398
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@1a202a2d
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@3eacda7f
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@495f5746
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@23f1f906

所以我来到stack overflow,找到了这个建议我设置 statementCacheNumDeferredCloseThreads1 . 我做到了,我明白了 DEADLOCK 不太频繁,而且只在负载平衡器后面的少数服务器上,而不是在所有服务器上。
日志现在看起来有些不同,但在死锁期间,查询仍然很长:

10 Oct 2018 06:33:32,037 [WARN]  (Timer-0) com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@4f39ad63 -- APPARENT DEADLOCK!!! Complete Status: 
        Managed Threads: 3
        Active Threads: 3
        Active Tasks: 
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@34dee200 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@3727ee6b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask@4afb8b9 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        Pending Tasks: 
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@384a3b5b
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@7bc700b0
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@731bfd15
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@a88e9bf
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@63f18b56
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@20f0c518
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@caf7746
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@41a7a27d
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@2ee32a24
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@81df2e5
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@7f7fa1e7
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@337503f
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@34b2f877
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@53dfbede
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@512d5ddb
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@68a25969
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@4bf0754a
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@65770ba4
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@5e0f4154
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@249c22ed
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@6c8e5911
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@3179550f
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@15d8a795
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@50966489
                com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@4ecee95b
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@35640ca0
                com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@6550f196
                com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@6816399
                com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@3fbcd623
Pool thread stack traces:
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
                com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
                com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
                com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask.run(GooGooStatementCache.java:404)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
                com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
                com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
                com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask.run(GooGooStatementCache.java:404)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
                com.mysql.jdbc.PreparedStatement.realClose(PreparedStatement.java:2765)
                com.mysql.jdbc.StatementImpl.close(StatementImpl.java:541)
                com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
                com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StatementCloseTask.run(GooGooStatementCache.java:404)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

你知道怎么解决吗?我可以尝试完全禁用语句缓存,但我担心性能会受到总体影响。其他相关参数:

minPoolSize = 30
maxPoolSize = 30
maxStatements = 100
unreturnedConnectionTimeout = 500
idleConnectionTestPeriod = 60
acquireIncrements = 3
C3p0 version = 0.9.1.2

编辑:我忘了提一下,在这个改进过程中,我看到的死锁更少,我也增加了 maxStatements 这就可以解释这种改进。不过现在我才明白https://github.com/swaldman/c3p0/issues/53 上面写着 version 0.9.2 引入此新参数 statementCacheNumDeferredCloseThreads . 我的版本太旧了。我没有得到关于此参数不存在的警告/错误。

tquggr8v

tquggr8v1#

也许太迟了,但你有没有试着增加 numHelperThreads ?

相关问题