优化tomcat启动时间 [英] Optimizing tomcat startup time

查看:168
本文介绍了优化tomcat启动时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序非常庞大,包含例如web-inf / lib中的310个jar,总共100Mb。启动服务器,此步骤需要13秒:

My application is pretty large, containing for instance 310 jars in web-inf/lib for a total of 100Mb. Starting the server, this step below takes 13s:

Sep 16, 2014 1:05:33 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.47\webapps\ROOT

应用程序依赖网页片段和注释来正确启动。

The application relies on web-fragment and annotations to start properly.

我尝试了以下内容以跳过13s扫描时间:

I tried the following to skip the 13s scanning time:


  • 修改 conf / context.xml,属性为logEffectiveWebXml =true

catalina run 2> web-complete.log

从中提取 web.xml 片段 web-complete.log ,保存在 webapps \ ROOT \web-inf \web.xml

extract the web.xml snippet from web-complete.log, save it under webapps\ROOT\web-inf\web.xml

如果我开始申请,我仍然会看到13秒的扫描时间。在上面的snipet中,metadata-complete已经设置为true。

If I start my application, I still see 13s scanning time. metadata-complete was already set to "true" in the snipet above.

将以下语句添加到web.xml后,完全跳过13s,但这次我的应用程序无法开始了:

After adding the following statement to web.xml skips the 13s altogether, but this time my application cannot start anymore:

<absolute-ordering />

1)在我的情况下,使tomcat快速启动的正确方法是什么?

1) What would be the proper way to make tomcat start fast in my case ?

2)你能解释为什么元数据完整对13s没有帮助吗?

2) Can you explain why metadata-complete does not help on the 13s ?

3)我的web.xml是完成,为什么不允许应用程序启动?

3) Altough my web.xml is complete, why does not allow the app to start ?

谢谢,

推荐答案

您可能认为默认情况下,Tomcat在部署您的Web应用程序时执行的操作效率很低,而且如果您做出正确的更改,您可以使用它,并使您的Web应用程序启动速度更快。这些都不是安全的假设。 Tomcat往往非常高效,甚至处理大型web应用程序。

You are probably assuming that Tomcat is, by default, doing something inefficient when deploying your webapp, and that if you make just the right change you can kludge around it and make your webapp start much faster. Those are not safe assumptions to make. Tomcat tends to be very efficient, even handling large webapps.

听起来我的webapp足够大,JDK无法加载大量的类并在不到13秒的时间内实例化大量对象。时间可能主要用于实例化和初始化servlet及其所需的所有内容,如果您的webapp在提供请求之前有许多大型子系统要初始化,那么这是一项非常大的工作。完成所有这些操作肯定需要几十秒,在此期间,解析配置文件的时间不多,甚至打开JAR来查找和解析一些文件。

It sounds to me like your webapp is large enough where the JDK is not able to load that huge number of classes and instantiate that large number of objects in less time than 13 seconds. The time is likely spent mainly in instantiating & initializing servlets and everything that they require, which is a very large amount of work to do if your webapp has many large subsystems to initialize before serving requests. Doing all of that can certainly take tens of seconds, and during that time not much of it is spent parsing config files, even opening JARs to find and parse some.

为什么我不知道你的webapp无法以静态元数据完整部署描述符开始,部分原因是因为你没有说出它失败时失败的具体方式。但是,通过将metadata-complete设置为true,您可能已经绕过了webapp所依赖的webapp启动的必要部分。

Why your webapp fails to start with a static metadata-complete deployment descriptor, I don't know, in part because you're not saying it what specific way it's failing when it fails. But, it's likely that by setting metadata-complete to true you have bypassed a necessary part of webapp startup that your webapp depends on.

潜在的启动优化

您可能专门为大型Web应用程序配置的东西可以节省Tomcat大量时间查看您的webapp文件:跳过您知道Tomcat的JAR不应扫描某些内容,例如Servlet 3片段和TLD。看看你的Tomcat的conf / catalina.properties文件......这些可配置的系统属性在那里:

Something that you might configure specifically for your large webapp that could save Tomcat a significant amount of time looking through your webapp's files is: skipping JARs that you know Tomcat shouldn't scan for certain things such as Servlet 3 fragments and TLDs. Have a look at your Tomcat's conf/catalina.properties file.. these configurable system properties are in there:

# Additional JARs (over and above the default JARs listed above) to skip when
# scanning for Servlet 3.0 pluggability features. These features include web
# fragments, annotations, SCIs and classes that match @HandlesTypes. The list
# must be a comma separated list of JAR file names.
org.apache.catalina.startup.ContextConfig.jarsToSkip=

# Additional JARs (over and above the default JARs listed above) to skip when
# scanning for TLDs. The list must be a comma separated list of JAR file names.
org.apache.catalina.startup.TldConfig.jarsToSkip=tomcat7-websocket.jar

添加Tomcat搜索这些JAR时应该跳过的所有JAR,我的猜测是Tomcat启动webapp的部分将更快完成。提前多久取决于webapp。

Add all of your JARs that should be skipped when Tomcat is searching for these, and my guess is that Tomcat's part of starting your webapp will complete sooner. How much sooner depends on the webapp.

这篇关于优化tomcat启动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆