Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add TOC. Minor wording tweaks.

How do I make Tomcat startup faster?

Table of Contents

This section provides several recommendations on how to make your web application and Apache Tomcat as a whole to start up faster.

Before we continue to specific tips and tricks, the general advice is that if Tomcat hangs or is not responsive, you have to perform diagnostics. That is to take several thread dumps to see what Tomcat is really doing. See Troubleshooting and Diagnostics page for details.

...

The Servlet 3.0 specification (chapter 8) introduces introduced support for several "plugability features". Those exist to simplify a structure of a web application and to simplify plugging of additional frameworks. Unfortunately, these features require scanning of JAR and class files, which may take noticeable time. Conformance to the specification requires that the scanning were performed by default, but you can configure your own web application in several ways to avoid it (see below). It is also possible to configure which JARs Tomcat should skip.

...

Remove any JAR files you do not need. When searching for classes every JAR file needs to be examined to find the needed class. If the jar file is not there - there is nothing to search.

Note that a web application should never have its own copy of Servlet API or Tomcat classes. All those are provided by the container (Tomcat) and should never be present in the web application. If you are using Apache Maven, such dependencies should be configured with <scope>provided</scope>. See also a stackoverflow page.

...

With Tomcat 7.0.23+ you can configure it to start several web applications in parallel. This is disabled by default but can be enabled by setting the startStopThreads attribute of a Host to a value greater than one.

Other

Memory

Tweak memory parameters - Google is your friend.

Config

Trim the config files as much as possible. XML parsing is not cheap. The less there is to parse - the faster things will go.

Web application

  1. Remove any web applications that you do not need. (So remove the all the web applications installed with tomcat) 2. Make sure your code is not doing slow things. (Use a profiler)

...