【发布时间】:2019-12-31 22:34:54
【问题描述】:
我们正在使用休眠和 MySql。我们使用 c3p0 创建一个连接池。根据我的研究,我在我的 persistence.xml 文件中提出了以下这些设置。 据我了解,数据库连接数不应低于最小值 10,当连接时间达到 14400(4 小时)时,它将被关闭并重新连接。
<property name="hibernate.c3p0.min_size" value="10" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.acquire_increment" value="10" />
<property name="hibernate.c3p0.max_statements" value="1000" />
<property name="hibernate.c3p0.numHelperThreads" value="30" />
<property name="hibernate.c3p0.timeout" value="14400" />
<property name="hibernate.c3p0.maxIdleTimeExcessConnections" value="1800" />
<property name="hibernate.c3p0.validate" value="false" />
<property name="hibernate.c3p0.idle_test_period" value="3600" />
<property name="hibernate.c3p0.preferredTestQuery" value="select id from contact limit 1" />
<property name="hibernate.c3p0.acquireRetryAttempts" value="100" />
<property name="hibernate.c3p0.acquireRetryDelay" value="1000" />
<property name="hibernate.c3p0.breakAfterAcquireFailure" value="true" />
使用这个查询我监控连接。我看到连接数从 10 开始,对于空闲连接,处理时间爬升到 3600 并根据 idle_test_period 重置。但是过了一天左右,我再次检查,发现连接数减少到 9。到周末连接数下降到 6。当连接数达到 1 时,程序将锁定而不抛出尝试运行数据库查询时出现异常。
SELECT
performance_schema.threads.PROCESSLIST_ID,
performance_schema.threads.PROCESSLIST_USER,
performance_schema.threads.PROCESSLIST_HOST,
performance_schema.threads.PROCESSLIST_TIME
FROM performance_schema.threads
WHERE performance_schema.threads.PROCESSLIST_USER = 'loginname'
ORDER BY performance_schema.threads.PROCESSLIST_HOST, performance_schema.threads.PROCESSLIST_TIME;
正如我所说,空闲连接的 PROCESS_TIME 上升到 3600,但昨天我看到一个爬升到超过 17000,到第二天早上连接被关闭,我的连接总数下降到 5 个。
这里有什么我遗漏的吗?打开的连接是否应该保持在至少 10 个?这些设置中是否存在使连接无法保持打开或保持的东西?
【问题讨论】: