druid获取连接超时异常排查
druid
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
项目地址:https://gitcode.com/gh_mirrors/druid/druid
免费下载资源
·
1 现象com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60011
at com.alibaba.druid.pool.DruidDataSource.pollLast(DruidDataSource.java:1068)
at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:748)
at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:640)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
at cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:33)
at cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)
at cn.egame.common.data.BaseDao.getObject(BaseDao.java:462)
at cn.egame.common.data.BaseDao.getInt(BaseDao.java:233)
at cn.egame.core.gc.TerminalServiceDao.getTerminalIdByUACode(TerminalServiceDao.java:30)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
根据GetConnectionTimeoutException此异常,初步怀疑:(1) mysql连接不上,排查通mysql过mysql客户端能够连接上mysql,
且mysql的连接数并未被占满。
(2)连接泄露2 分析 System.out.println("pool dump : " + pool.dump());
//pool是DruidDataSource打印信息:pool dump :{ CreateTime:"2013-06-08 19:23:38", ActiveCount:200, PoolingCount:0,
CreateCount:319, DestroyCount:119, CloseCount:201403, ConnectCount:213737, Connections:[ ]}
ActiveCount:当前被占用的连接数,配置文件中MaxActive=200,最大连接数设置为200。PoolingCount:闲置的连接数。结论:druid连接泄露。
3 排查pool.setRemoveAbandoned(true);//会影响性能,只有在排查连接泄露的时候,才打开 System.out.println("activeStackTrace : "+
pool.getActiveConnectionStackTrace());//pool.setRemoveAbandoned(true)设置为true的时候,才有活跃连接的堆栈信息,
不然后没有打印信息:activeStackTrace : [java.lang.Thread.getStackTrace(Thread.java:1436)com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:678)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:35)
cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)cn.egame.common.data.BaseDao.main(BaseDao.java:33),
java.lang.Thread.getStackTrace(Thread.java:1436)com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:678)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:35)
cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)cn.egame.common.data.BaseDao.main(BaseDao.java:34)]
我们就可以根据活跃连接的堆栈信息,看到具体的哪个业务方法持有了连接未释放。
at com.alibaba.druid.pool.DruidDataSource.pollLast(DruidDataSource.java:1068)
at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:748)
at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:640)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
at cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:33)
at cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)
at cn.egame.common.data.BaseDao.getObject(BaseDao.java:462)
at cn.egame.common.data.BaseDao.getInt(BaseDao.java:233)
at cn.egame.core.gc.TerminalServiceDao.getTerminalIdByUACode(TerminalServiceDao.java:30)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
根据GetConnectionTimeoutException此异常,初步怀疑:(1) mysql连接不上,排查通mysql过mysql客户端能够连接上mysql,
且mysql的连接数并未被占满。
(2)连接泄露2 分析 System.out.println("pool dump : " + pool.dump());
//pool是DruidDataSource打印信息:pool dump :{ CreateTime:"2013-06-08 19:23:38", ActiveCount:200, PoolingCount:0,
CreateCount:319, DestroyCount:119, CloseCount:201403, ConnectCount:213737, Connections:[ ]}
ActiveCount:当前被占用的连接数,配置文件中MaxActive=200,最大连接数设置为200。PoolingCount:闲置的连接数。结论:druid连接泄露。
3 排查pool.setRemoveAbandoned(true);//会影响性能,只有在排查连接泄露的时候,才打开 System.out.println("activeStackTrace : "+
pool.getActiveConnectionStackTrace());//pool.setRemoveAbandoned(true)设置为true的时候,才有活跃连接的堆栈信息,
不然后没有打印信息:activeStackTrace : [java.lang.Thread.getStackTrace(Thread.java:1436)com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:678)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:35)
cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)cn.egame.common.data.BaseDao.main(BaseDao.java:33),
java.lang.Thread.getStackTrace(Thread.java:1436)com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:678)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:624)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:614)
cn.egame.common.data.dbpool.ConnectionManager.getConnection(ConnectionManager.java:35)
cn.egame.common.data.BaseDao.getConnection(BaseDao.java:142)cn.egame.common.data.BaseDao.main(BaseDao.java:34)]
我们就可以根据活跃连接的堆栈信息,看到具体的哪个业务方法持有了连接未释放。
GitHub 加速计划 / druid / druid
27.83 K
8.56 K
下载
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
最近提交(Master分支:3 个月前 )
f060c270 - 13 天前
1613a765
* Improve gaussdb ddl parser
* fix temp table 15 天前
更多推荐
已为社区贡献1条内容
所有评论(0)