如何缩小DB连接池?

时间:2022-11-03 17:00:39

I am using Apache DBCP with JNDI in my tomcat container to pool connections to a mysql database. Everything works fine but a problem i am seeing is that once a pconnection is pooled it is never released. So after a load spike connection sit their forever sleeping. Is their a way to shrink the pool through context.xml parameters? here is my ocnfiguration:

我在我的tomcat容器中使用Apache DBCP和JNDI来连接到mysql数据库的连接。一切正常,但我看到的一个问题是,一旦pconnection被汇集,它就永远不会被释放。因此,在加载峰值连接后,他们会永远沉睡。他们是通过context.xml参数缩小池的方法吗?这是我的配置:

        defaultAutoCommit="false"
        defaultTransactionIsolation="REPEATABLE_READ"
        auth="Container"
        type="javax.sql.DataSource"
        logAbandoned="true" 
        removeAbandoned="true"
        removeAbandonedTimeout="300" 
        maxActive="-1"
        initialSize="15"
        maxIdle="10"
        maxWait="10000" 
        username="user"
        password="password"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost/mydb"/>

3 个解决方案

#1


Try to set minEvictableIdleTimeMillis to lower value than its default, which is 1000*60*30.

尝试将minEvictableIdleTimeMillis设置为低于其默认值的值,即1000 * 60 * 30。

#2


try to use c3p0 connection pool`~~

尝试使用c3p0连接池`~~

#3


In comparable situations I've used Tomcat's JMX adapter to tweak the settings of the connection pool. This can be used both, to increase and to decrease thesize of the pool. It is therefore a good idea to enable JMX remote access to the servlet container at least in production environments, just to have some chance to react on exceptional operational situations.

在类似的情况下,我使用Tomcat的JMX适配器来调整连接池的设置。这可以用于增加和减少池的大小。因此,至少在生产环境中启用JMX远程访问servlet容器是个好主意,只是为了有机会对特殊的操作情况作出反应。

#1


Try to set minEvictableIdleTimeMillis to lower value than its default, which is 1000*60*30.

尝试将minEvictableIdleTimeMillis设置为低于其默认值的值,即1000 * 60 * 30。

#2


try to use c3p0 connection pool`~~

尝试使用c3p0连接池`~~

#3


In comparable situations I've used Tomcat's JMX adapter to tweak the settings of the connection pool. This can be used both, to increase and to decrease thesize of the pool. It is therefore a good idea to enable JMX remote access to the servlet container at least in production environments, just to have some chance to react on exceptional operational situations.

在类似的情况下,我使用Tomcat的JMX适配器来调整连接池的设置。这可以用于增加和减少池的大小。因此,至少在生产环境中启用JMX远程访问servlet容器是个好主意,只是为了有机会对特殊的操作情况作出反应。