MySQL/Hibernate - How do I debug a MySQL pooled connection that keeps dropping?

后端 未结 3 1656
离开以前
离开以前 2021-02-14 02:51

For months, my web application ran smoothly, but for the past week or two, it keeps dropping its connection to MySQL server. I\'m not a DBA guy and have no idea how to debug thi

3条回答
  •  情歌与酒
    2021-02-14 03:20

    It seems your connection pool cannot return a free connection to Hibernate within timeout duration. This happens because your application have very long transactions or transaction dead locks. You can try following options to fix the bug.

    1. change your connection pool size in following line

      5

    make the pool size about 10 and test. You should keep your eye on the count of connections to your database. If it exceeds the mysql database connection limitations change max_connections of mysql server and keep testing.

    1. Use an another connection pool. I recommend to use apache commons dbcp2. Maven dependencies of dbcp2 as follows.

      org.apache.commons commons-dbcp2 2.1

    Add dbcp2 into your POM then config dbcp2 with your application.

    If it was the solution your application had only long transactions. Sometimes it may minimize the occurrence, and if it is still happening definitely your application have transaction dead locks. So you have to identify what are the possible problems with your code.

    There are other alternative solutions such changing the waiting timeout to a higher value. But it is not good for your application performance and it doesn't make any sense for transaction dead locks. Finally you should remember to care about transaction management and database structure in your further developments for better performance of database.

提交回复
热议问题