记一次tomcat启动慢的问题

相同的war包在本地启动大概在一分钟左右,现场测试环境里启动确需要八九分种,本地模拟未发现明显问题。查看现场发过来的日志

01-Jul-2020 09:37:05.340 INFO [localhost-startStop-1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$fe80b2f4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
01-Jul-2020 09:45:28.266 INFO [localhost-startStop-1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'dataSource' of type [class com.alibaba.druid.pool.DruidDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
01-Jul-2020 09:45:28.279 INFO [localhost-startStop-1] org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties Loading properties file from URL [file:/home/cloudwalk/apache-tomcat-8.5.46/webapps/ibis/WEB-INF/classes/spring/init-config.properties]

这里我们明显看到spring容器加载dataSource的时候耗费了8分多钟,感觉问题出在这块,然后本地直接使用spring容器加载bean,因为连接池这里使用的是druid的连接池:

记一次tomcat启动慢的问题

所以我在源码的dataSource的init方法里面加上了断点。代码的大概意思是不断地创建连接,直到线程池里面的连接数和初始化的连接数一样大。

记一次tomcat启动慢的问题

发现本地也会在创建连接池的时候卡顿一下,耗时在3s,见志

02-Jul-2020 18:53:46.650 ÐÅÏ¢ [localhost-startStop-1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$b1ccae49] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
02-Jul-2020 18:53:49.140 ÐÅÏ¢ [localhost-startStop-1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean 'dataSource' of type [class com.alibaba.druid.pool.DruidDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
02-Jul-2020 18:53:49.145 ÐÅÏ¢ [localhost-startStop-1] org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties Loading properties file from URL [file:/E:/apache-tomcat-8.5.35/webapps/ibis/WEB-INF/classes/spring/init-config.properties]

猜测可能现场这里连接比较慢,让现场把initialSize 这个参数改小一点==发现tomcat启动速度明显提升。大家设定初始化连接池的时候记得不要设置的太大。

问题终于得到了解决==