Tomcat 8 应用程序初始化缓慢

Tomcat 8 应用程序初始化缓慢

我发现了很多关于 Tomcat“启动缓慢”的帖子,但没有一个与 Web 应用程序初始化缓慢有关。

我使用的是 Tomcat 8 和 Java 8。大多数时候它只使用一小部分内存和 CPU 容量。服务器启动很快,但 Web 应用程序本身的初始化速度很慢(十几个简单的应用程序需要 10-15 分钟)。

一些可能相关的细节:

  • 服务器是运行在 Java 8 上的 Tomcat 8。
  • 所有应用程序都是用 Spring MVC 构建的。
  • 所有应用程序都依赖于完全相同的开源库堆栈,其类路径在 catalina.properties common.loader 中指定。(cas、commons-beanutils、commons-dbcp2、cxf、itext、jackson、jt400、mssql jdbc driver、poi、sitemesh 和 spring,以及它们所依赖的库)
  • 我们有一个类似的服务器,也在 Java 8 上运行 Tomcat 8,但使用 Java 6 模拟来运行较旧的应用程序。这些应用程序依赖于相同开源库的较旧版本。这些旧应用程序服务器确实在合理的时间内启动。唯一明显的区别是开源打包模型(旧方法将它们收集到几十个 jar 中,而现代方法则是收集数百个较小的 jar)。
  • 使用相同较新版本库堆栈的本机 Java 8 应用程序启动速度更快,只需几秒钟。

在 Web 应用程序初始化并可用之前等待 10-15 分钟太长了。我认为我们做错了什么导致初始化如此缓慢。

我可以寻求一些关于如何排除故障并解决这个问题的提示吗?

谢谢。


如果相关的话,这是 catalina.log 的开头,包括 Tomcat 附带的前几个应用程序:


26-Jun-2019 05:59:02.952 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.28
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Oct 7 2015 18:25:21 UTC
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.28.0
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows Server 2012 R2
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            6.3
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             D:\java\jdk8.144\jre
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_144-b01
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         D:\tomcat\apache-tomcat-8.0.28
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         D:\tomcat\apache-tomcat-8.0.28
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\tomcat\apache-tomcat-8.0.28
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=D:\tomcat\apache-tomcat-8.0.28
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=D:\tomcat\apache-tomcat-8.0.28\endorsed
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\tomcat\apache-tomcat-8.0.28\temp
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=D:\tomcat\apache-tomcat-8.0.28\conf\logging.properties
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xdebug
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: exit
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms3000m
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx4000m
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.1.33 using APR version 1.5.1.
26-Jun-2019 05:59:02.967 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
26-Jun-2019 05:59:04.030 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.1m 19 Mar 2015)
26-Jun-2019 05:59:04.561 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-80"]
26-Jun-2019 05:59:04.623 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-443"]
26-Jun-2019 05:59:05.108 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Jun-2019 05:59:05.108 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
26-Jun-2019 05:59:05.123 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 3442 ms
26-Jun-2019 05:59:05.170 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
26-Jun-2019 05:59:05.170 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.28
26-Jun-2019 05:59:05.202 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\tomcat\apache-tomcat-8.0.28\webapps\docs
26-Jun-2019 05:59:40.780 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
26-Jun-2019 05:59:40.936 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\tomcat\apache-tomcat-8.0.28\webapps\docs has finished in 35,750 ms
26-Jun-2019 05:59:40.936 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\tomcat\apache-tomcat-8.0.28\webapps\examples
26-Jun-2019 06:00:11.998 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
26-Jun-2019 06:00:12.467 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\tomcat\apache-tomcat-8.0.28\webapps\examples has finished in 31,531 ms

答案1

为 Xms 设置一个高值似乎有点过分。尝试保留默认值,最小 3g 到最大 4g 的范围很窄。您的应用可能需要这个 RAM,但它们应该会自行增长以填满空间

相关内容