如何在Tomcat启动期间避免分钟延迟

时间:2013-03-01 11:21:36

标签: mysql tomcat bonecp

在许多生产服务器上的服务器启动分钟期间,我们遇到了严重的延迟,但无法在测试环境中重现这一点。有没有人有任何关于如何调试或修复此问题的建议?它发生在Tomcat 6和Tomcat 7

我们的设置是 雄猫7 春季3.1.2 Hibernate 4.1.7 BoneCP 0.7.1 Mysql连接5.1.23 新遗物

似乎与骨骼CP相关

[MSA] DEBUG [2013-02-18 14:58:34,903] DefaultListableBeanFactory.invokeInitMethods(1498) | Invoking afterPropertiesSet() on bean with name 'dataSource'
[MSA] DEBUG [2013-02-18 14:58:34,919] BoneCPDataSource.maybeInit(148) | JDBC URL = jdbc:mysql://1.1.1.1:3306/db_prod?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&sessionVariables=FOREIGN_KEY_CHECKS=0, Username = xyz, partitions = 3, max (per partition) = 30, min (per partition) = 10, helper threads = 3, idle max age = 3 min, idle test period = 2 min
[MSA] DEBUG [2013-02-18 15:01:11,474] DefaultListableBeanFactory.doGetBean(245) | Returning cached instance of singleton bean 'managerTx'

我们的骨骼CP设置如下

<bean id="dataSource"
   class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
   <property name="targetDataSource">
       <ref local="mainDataSource" />
   </property>
</bean>

<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="idleMaxAgeInMinutes" value="3"/>
    <property name="idleConnectionTestPeriodInMinutes" value="2"/>
    <property name="maxConnectionsPerPartition" value="30"/>
  <property name="minConnectionsPerPartition" value="10"/>
  <property name="partitionCount" value="3"/>
  <property name="acquireIncrement" value="2"/>
  <property name="statementsCacheSize" value="100"/>
  <property name="releaseHelperThreads" value="3"/>
</bean>

基于Mindas的建议。这是等待期间发生的事情的堆栈跟踪

"pool-3-thread-1" prio=10 tid=0x00007fd26c004000 nid=0x5c7e runnable   [0x00007fd2c4722000]
java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114)
    at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161)
    at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189)
    - locked <0x00000000ccf12490> (a com.mysql.jdbc.util.ReadAheadInputStream)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3049)
    at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:597)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1084)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
    - locked <0x00000000ccf04310> (a com.mysql.jdbc.JDBC4Connection)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256)
    at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211)
    at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170)
    at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:371)
    at com.jolbox.bonecp.BoneCPDataSource.maybeInit(BoneCPDataSource.java:150)
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:112)
    at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy.afterPropertiesSet(LazyConnectionDataSourceProxy.java:163)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    - locked <0x00000000dc56d780> (a java.util.concurrent.ConcurrentHashMap)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    - locked <0x00000000dc56d780> (a java.util.concurrent.ConcurrentHashMap)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

1 个答案:

答案 0 :(得分:2)

发送kill -3(如果在Unix上,或corresponding signal,如果在Windows上)发送到您的Tomcat进程ID时,它会被卡住。您将在catalina.out中看到所有具有完整堆栈跟踪的线程。

编辑:堆栈跟踪快照似乎正在启动连接。您可以验证(使用本地mysql客户端)您可以连接而没有任何延迟(提示:DNS问题)并快速执行命令 - 使用完全与JDBC相同的配置?