How to get your Tomcat to pounce on startup, not crawl

Stella981
• 阅读 1125

As promised in my last few posts, I am finally going to give you a couple of Tomcat tips and tricks, that can seriously speed up your Tomcat startup time. In all fairness, they are simple configurations, and I am not the first to find them, not even the first CFMLer to find them. This is how I got my Tomcat startup from 164 seconds, down to 8 seconds, a gain of 156 seconds, in 1 line of code.

The first thing you have to remember, whether we are running Lucee, or Railo, we are running on the JVM. Tomcat is a Java Servlet and it is much more powerful than our lil old cfml engines. Knowing this, Tomcat has a few settings in given files that don’t apply to MOST of our CFML servers… the big one, is the JAR scanning.
Note: There could be an odd chance this might affect some weird setup, I’m just not sure what at this point.

"The Jar Scanner element represents the component that is used to scan the web application for JAR files and directories of class files. It is typically used during web application start to identify configuration files such as TLDs or web-fragment.xml files that must be processed as part of the web application initialization."

Taken from the Apache Tomcat 8 Configuration Referencehttp://tomcat.apache.org/tomcat-8.0-doc/config/jar-scanner.html

For every host / context, tomcat is scanning every folder it knows about (slight exaggeration), and you can see in the logs that it fails to find TLDs and configuration information, that it warns you that you could save time.

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.

So we are wasting time here, great, how do we fix it. There are two solutions.

// File: conf/context.xml

Inside the Context element, you have watched resources, but you can also set JarScanner with some params. By default scanAllDirectories, scanAllFiles, and scanBootstrapClassPath are set to false, but scanClassPath is true. Setting this, will set that to false too.

Restart Tomcat, and you should see the startup time disappear.
My dev machine right now, has only a few Host setup in my Server.xml, since i have been experimenting with lots of alternatives to using manually coded Hosts, but even with that, my startup times looked like this.

12-Feb-2015 21:43:39.592 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 23576 ms // Versus 12-Feb-2015 21:48:40.840 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3287 ms

Now, if you are concerned, and you want some of your JARs to be scanned, the 2nd option will be better for you.
Note, I am referring to Tomcat 8, Tomcat 7 had 3 settings in the catalina.properties, not just 1.

// File: conf/catalina.properties approx line 96 for standard Lucee Express

tomcat.util.scan.StandardJarScanFilter.jarsToSkip= \ bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,\ annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,\ catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,\ catalina-tribes.jar,\ jasper.jar,jasper-el.jar,ecj-*.jar,\ tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,\ tomcat-dbcp.jar,tomcat-jni.jar,tomcat-spdy.jar,tomcat-websocket.jar,\ tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,\ tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,\ tomcat-jdbc.jar,\ tools.jar,\ commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,\ commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,\ commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,\ commons-math*.jar,commons-pool*.jar,\ jstl.jar,\ geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,\ ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,\ jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,\ xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,\ junit.jar,junit-*.jar,ant-launcher.jar,\ cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,\ jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,\ xom-*.jar

This property lists all of the jars to skip… so if you want, you can name all of the jars to skip, but it extensive, and daunting.
Or you can do the equivalent of the last setting, and set this line to

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=*

This will skip all JARS, and you will see almost identical startup.
That is all of the magic, its 1 setting, and it saves about 5-6 seconds per Host on each and every startup. I previous had 20-30 sites and was waiting for up to 5 minutes, which is ridiculous. Especially considering we do not need scanning.

As I mentioned earlier, Tony Junkes was looking into this when he first moved to Tomcat 8, and posted his article on Fixing Slow Railo Startup on Tomcat 8
Tony goes into more details on this findings, plus a few other bugs he found, so I will not repeat that, please go read his article.

At the same time we posted that, I was still running Tomcat 7 and round that there were two other settings, shown below, but the best performance increase was the same setting still available in Tomcat 8

org.apache.catalina.startup.ContextConfig.jarsToSkip=* = 150 second gain
org.apache.catalina.startup.TldConfig.jarsToSkip=*     = No real gain
tomcat.util.scan.DefaultJarScanner.jarsToSkip=*  156 second gain

Although this post is aimed at Tomcat 8, if you are still on Tomcat 7, it still might be fruitful to test this out.

If anyone knows why you might need to leave this on, in our normal CFML running servers, please share that information.

I hope it was worth the wait, go try it.
Please give some feedback in the comments to the BEFORE and AFTER times, and the number of Host records if you are up to counting them, please.

My dev server before the Host cutting was 95% savings on 25 hosts
Current dev server, it was 86.1% savings with 3 hosts.

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
3年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这