我正在努力了解数据源如何运行验证。我有一个连接池,它在Firebird数据库上运行查询,但是池中连接很少会引发错误,如
Insufficient memory to allocate page buffer cache [SQLState:HY013, ISC error code:335544691
我不确定为什么数据源不会使用验证查询使它们无效。我创建的数据源不是容器管理的,因此不确定这是否是未调用验证查询的原因。
我创建了一个数据源bean并在Spring bean上注册它,如下所示。
builder.beans {
"${beanName}"(org.apache.tomcat.jdbc.pool.DataSource) {
driverClassName = "${configuration.driver}"
url = configuration.connectionUrlPrefix
username = configuration.userName
password = configuration.password
maxActive = properties.maxActive
maxIdle = properties.maxIdle
minIdle = properties.minIdle
initialSize = properties.initialSize
maxWait = properties.maxWait
validationQuery = properties.validationQuery
validationInterval = properties.validationInterval
testWhileIdle = properties.testWhileIdle
testOnBorrow = properties.testOnBorrow
logAbandoned = properties.logAbandoned
removeAbandoned = properties.removeAbandoned
removeAbandonedTimeout = properties.removeAbandonedTimeout
timeBetweenEvictionRunsMillis = properties.timeBetweenEvictionRunsMillis
minEvictableIdleTimeMillis = properties.minEvictableIdleTimeMillis
}
}
堆栈跟踪:
2018-05-02 11:30:52,766 [ajp-bio-8012-exec-7] ERROR StackTrace - Full Stack Trace:
java.sql.SQLException: Insufficient memory to allocate page buffer cache [SQLState:HY013, ISC error code:335544691]
at org.firebirdsql.gds.ng.FbExceptionBuilder$Type$1.createSQLException(FbExceptionBuilder.java:498)
at org.firebirdsql.gds.ng.FbExceptionBuilder.toFlatSQLException(FbExceptionBuilder.java:299)
at org.firebirdsql.gds.ng.wire.AbstractWireOperations.readStatusVector(AbstractWireOperations.java:135)
at org.firebirdsql.gds.ng.wire.AbstractWireOperations.processOperation(AbstractWireOperations.java:199)
at org.firebirdsql.gds.ng.wire.AbstractWireOperations.readSingleResponse(AbstractWireOperations.java:166)
at org.firebirdsql.gds.ng.wire.AbstractWireOperations.readResponse(AbstractWireOperations.java:150)
at org.firebirdsql.gds.ng.wire.AbstractWireOperations.readGenericResponse(AbstractWireOperations.java:252)
at org.firebirdsql.gds.ng.wire.version10.V10WireOperations.authReceiveResponse(V10WireOperations.java:52)
at org.firebirdsql.gds.ng.wire.version10.V10Database.authReceiveResponse(V10Database.java:566)
at org.firebirdsql.gds.ng.wire.version10.V10Database.attachOrCreate(V10Database.java:110)
at org.firebirdsql.gds.ng.wire.version10.V10Database.attach(V10Database.java:80)
at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:144)
at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:520)
at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:65)
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:117)
at org.firebirdsql.jdbc.FBDriver.connect(FBDriver.java:137)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:712)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:646)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:145)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
at javax.sql.DataSource$getConnection.call(Unknown Source)
at
答案 0 :(得分:0)
错误本身意味着Firebird尝试为页缓冲区缓存分配内存,但无法(因为操作系统内存不足,或者达到了进程可用的最大内存量)。该问题与验证查询无关,堆栈跟踪显示它在创建新连接时发生。如果池无法分配新连接来为您的请求提供服务,它将放弃。
根据我们在评论中的交换,看起来这个Firebird服务器配置为Classic Server(CS)或SuperClassic(SC)模式。在此模式下,页面缓冲区高速缓存是每个连接,而不是每个数据库(在SuperServer(SS)模式下,它是每个数据库)。结果,连接越多,内存消耗就越高。
这表示您要分配的连接数太多,或者配置的缓存页数太多(最具体的配置 - 如果设置 - 适用):
firebird.conf
设置DefaultDbCachePages
)设置得太高(CS / SC默认为75,SS为2048)gstat -h
输出)isc_dpb_num_buffers
/ num_buffers
使用Classic / SuperClassic,这会导致分配 NCachePages * Pagesize 字节的内存每个连接,其中Pagesize是数据库的页面大小(通常为8或16)千字节)。
例如,对于具有16kb页面大小的CS / SC,默认为75个缓冲区,每个连接需要1228800(1.2 MB)的内存用于缓存),因此100个连接需要122 MB(忽略其他内存需求)高速缓冲存储器)。
另一方面,如果此设置已更改(全局,数据库或每个连接设置)到例如9999页,则每个连接需要163 MB内存,100个连接需要16 GB
要解决此问题,您需要执行以下一个或多个步骤:
最后两个可能导致性能发生重大变化(可能是正面的,可能是负面的),所以应该仔细测试。
作为一种解决方法,如果您无法在短时间内让所有者更改配置,请考虑将连接属性num_buffers=75
(或类似的低数字)添加到您的连接属性中。