Tomcat Grails2.3.4池为空。无法在30秒内获取连接
我们在Tomcat7.0.30中看到了grails应用程序的崩溃。 Grails版本是2.2.4,去年运行非常稳定。 我尝试将grails版本切换到2.3.4,在测试环境中,它表现正常(没有任何问题)。 但当我在20分钟后投入生产时,我开始出现以下异常Tomcat Grails2.3.4池为空。无法在30秒内获取连接,tomcat,grails,gorm,Tomcat,Grails,Gorm,我们在Tomcat7.0.30中看到了grails应用程序的崩溃。 Grails版本是2.2.4,去年运行非常稳定。 我尝试将grails版本切换到2.3.4,在测试环境中,它表现正常(没有任何问题)。 但当我在20分钟后投入生产时,我开始出现以下异常 [ajp-bio-9009-exec-430] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100;
[ajp-bio-9009-exec-430] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000].. Stacktrace follows:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [ajp-bio-9009-exec-430] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000].
at grails.gorm.DetachedCriteria$_count_closure4.doCall(DetachedCriteria.groovy:686)
at grails.gorm.DetachedCriteria$_withPopulatedQuery_closure10.doCall(DetachedCriteria.groovy:931)
at org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure20.doCall(GormStaticApi.groovy:680)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:679)
at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:913)
at grails.gorm.DetachedCriteria.count(DetachedCriteria.groovy:684)
at grails.gorm.DetachedCriteria.count(DetachedCriteria.groovy:683)
at com.webbfontaine.wftaglib.BeanDataLoadController.doLoadData(BeanDataLoadController.groovy:30)
at com.webbfontaine.wftaglib.BeanDataLoadController$_closure1.doCall(BeanDataLoadController.groovy:14)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at org.josso.tc70.agent.SSOAgentValve.invoke(SSOAgentValve.java:684)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
在我们的应用程序中,对DB的所有查询都是通过Grails GORM完成的,我们不使用任何SQL或HQL查询
我的猜测是Grails2.3.4本身出了问题(有些连接没有正确关闭/返回到池中)
我是不是遗漏了什么东西或者它的圣杯问题?
有什么想法吗?Grails 2.3.x,这可能就是您的应用程序存在差异的原因。您可以检查池配置中的差异。我首先检查是否有线程“卡住”并保持db连接。您可以从JVM线程转储中看到这一点 通过向Java进程PID发送SIGQUIT(3)信号,可以在unix中进行线程转储。 您可以使用“kill-3pid”命令来执行此操作。线程转储转到stdout(默认情况下,stdout转到tomcat上的catalina.out)。它不会终止Java进程,因此您可以在生产环境中正常使用此方法 获取threaddump的另一种方法是使用“jstack PID”命令 通常,对一个零件进行几秒钟的后续转储是值得的。通过这种方式,您可以区分转储以查看哪些更改以及哪些保持不变。您通常必须手动进行微分。有。这些问题将在Grails2.3.6中修复 下面是一个MySQL优化数据源设置的示例
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/my_database"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "username"
password = "password"
properties {
// Documentation for Tomcat JDBC Pool
// http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes
// https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/tomcat/jdbc/pool/PoolConfiguration.html
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
ignoreExceptionOnPreLoad = true
// http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#JDBC_interceptors
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED // safe default
// controls for leaked connections
abandonWhenPercentageFull = 100 // settings are active only when pool is full
removeAbandonedTimeout = 120
removeAbandoned = true
// use JMX console to change this setting at runtime
logAbandoned = false // causes stacktrace recording overhead, use only for debugging
// JDBC driver properties
// Mysql as example
dbProperties {
// Mysql specific driver properties
// http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html
// let Tomcat JDBC Pool handle reconnecting
autoReconnect=false
// truncation behaviour
jdbcCompliantTruncation=false
// mysql 0-date conversion
zeroDateTimeBehavior='convertToNull'
// Tomcat JDBC Pool's StatementCache is used instead, so disable mysql driver's cache
cachePrepStmts=false
cacheCallableStmts=false
// Tomcat JDBC Pool's StatementFinalizer keeps track
dontTrackOpenResources=true
// performance optimization: reduce number of SQLExceptions thrown in mysql driver code
holdResultsOpenOverStatementClose=true
// enable MySQL query cache - using server prep stmts will disable query caching
useServerPrepStmts=false
// metadata caching
cacheServerConfiguration=true
cacheResultSetMetadata=true
metadataCacheSize=100
// timeouts for TCP/IP
connectTimeout=15000
socketTimeout=120000
// timer tuning (disable)
maintainTimeStats=false
enableQueryTimeouts=false
// misc tuning
noDatetimeStringSync=true
}
}
}
谢谢你的回答。我想用Grails2.3.x和“Commons DBCP”检查一下。您知道如何强制grails使用“Commons DBCP”吗?我认为您需要做类似的事情,更改数据源bean的类名。dbProperties配置将针对2.3.6进行修复,否则这些设置适用于以前的2.3.x版本Hibernate4(4.3.1版本)与Tomcat JDBC池拦截器有问题:。使用Hibernate 4.3.1时删除“StatementCache(max=200)”。该问题将在Hibernate 4.3.2()中修复