Administrator
发布于 2024-08-02 / 21 阅读
0
0

druid连接池活跃连接数满了导致应用假死问题

问题现象

2022-04-2210:09:38,520ERROR---[http-nio-9190-exec-90]o.a.c.c.c..[.[.[dispatcherservlet] :Servlet.service() for servlet [dispatcherServlet] in context with pathil threw exception iRequest processing failed, nested exception is ong.springframework.transaction.canotCreateTransactionException:Could not open JPA EntitvManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCDBCException:Unable to acquire JDBC Connection] with root cause
com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000,active 200,maxActive 200,creating 0
at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1329)
at com.libaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.iava:1148)
at com.alibabadruid.poota5ource.getConnection(DruidDatasource.iava:1128)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1118)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.iava:104)
  1. 使用druid的monitor监控页面查看连接数占用情况

  2. 判断连接是否正常

    异常情况:不相等/最大连接数配置的太小不满足业务实际需求

    正常情况:逻辑连接打开次数 - 逻辑连接关闭次数 = 活跃连接数

  3. 连接泄露检测

    1. 在应用连接池配置中增加removeAbandoned

              url: jdbc:mysql://xxxxxx:3306/xxxx?useSSL=false
              username: root
              password: xxxxxxxx
              initial-size: 5
              min-idle: 1
              maxActive: 200
              ....
              removeAbandoned: true
              removeAbandonedTimeout: 600
              logAbandoned: true
    2. 当再次出现连接泄露时查看druid监控或者程序后台日志,发现导致连接泄漏的具体代码

  4. RemoveAbandanded功能不建议在生产环境中使用,仅用于连接泄露检测诊断


评论