As it mentionned in this excellent article : https://wiki.apache.org/tomcat/HowTo/FasterStartUp, tomcat will be very faster to start-up if you add some parameter to the out-of-the-box version.

This table show How-To accomplished each case in Tomcat 7 or Tomcat 8 :

Tomcat 7 Tomcat 8

Disable scanning webapp

web.xml

web.xml

Disable scanning web-fragment jar

web.xml

web.xml

Excludes jars for scanning

system properties only

system properties or element in context

Disable WebSocket support

element in context

element in context

Disable JSP support

not available

element in context

Reduce SecureRandom instance

jvm option

jvm option

Now see some examples to each case

Configure web.xml

Disable scanning the web application

Put metadata-complete attribute to web-app tag.

<web-app metadata-complete="true">

…​

</web-app>

Disable scanning web-fragment jar

Add absolute-ordering tag

<web-app>

<absolute-ordering />

</web-app>

Configure context

There is 2 way to do this, regarding how the application is deployed :

  • If the application is packaging with the classic way (WAR for example)

    • this can be in META-INF/context.xml of the application

  • If the application is deployed with Tomcat 7 VirtualWebApp concept or Tomcat 8 Resources mecanism (see this article for more explanations)

    • this can be in server.xml file under the <Host> who defined the application

Excludes jars for scanning

Add JarScanner tag

<Context>

<JarScanner>

<JarScanFilter defaultTldScan="false"/>

</JarScanner>

</Context>

Disable WebSocket support

Put containerSciFilter attribute to Context tag

<Context containerSciFilter="org.apache.tomcat.websocket.server.WsSci">

…​

</Context>

Disable JSP support (only tomcat 8)

Put containerSciFilter attribute to Context tag

<Context containerSciFilter="org.apache.jasper.servlet.JasperInitializer">

…​

</Context>

Disable both WebSocket and JSP support (only tomcat 8)

Put containerSciFilter attribute to Context tag with RegExp

<Context containerSciFilter="org.apache.tomcat.websocket.server.WsSci|org.apache.jasper.servlet.JasperInitializer">

…​

</Context>

Configure JVM

Reduce SecureRandom instance to generate random

Set this option in the JVM who launch Tomcat (e.g. in JAVA_OPTS or CATALINA_OPTS environnment variable)

-Djava.security.egd=file:/dev/./urandom

Some performance tests examples

This tests are being executed on a simple web application with one REST service based on CXF and Spring.

This is not a real benchmark, it’s just for illustrate each options.

Tomcat 8 with WAR Tomcat 8 with Resources

out of the box

4647ms

7036ms

Disable scanning webapp

4611ms

6968ms

Disable scanning web-fragment jar

3898ms

5493ms

Excludes jars for scanning

3827ms

5343ms

Disable WebSocket support

3782ms

3777ms

Disable JSP support

Not tested

3760ms

Reduce SecureRandom instance

Not tested

Not tested

  • Tomcat 8 WAR

    • Start at 4647ms to 3782ms

  • Tomcat 8 Resources

    • Start at 7036ms to 3760ms

comments powered by Disqus