You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

How do I make Tomcat startup faster?

Jars

  1. Remove any jar files you don't need. When searching for classes every JAR file needs to be examined to find the needed class. Also during webapp startup, jar files are searched for TLD files. If the jar file is not there - there is nothing to search. 2. Tomcat 7.+: You can add jars that do not need to be scanned for TLD files, Annotations and Web fragments to the value of tomcat.util.scan.DefaultJarScanner.jarsToSkip property in conf/catalina.properties file. Maybe later there would be a more convenient way to configure this feature.

Memory

  1. Tweak memory parameters - Google is your friend.

Config

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

Webapp

  1. Make sure your code is not doing slow things. (Use a profiler) 2. Remove any webapps you don't need. (So remove the all the webapps installed with tomcat) 3. Add metadata-complete="true" attribute to the <web-app> element of your WEB-INF/web.xml file, if you do not need the features that are enabled by the default value of "false" of that attribute. This way Tomcat would not waste time scanning the libraries to autodiscover annotated classes and web fragments.

Starting several web applications in parallel

  1. 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.

Entropy Source

  1. Tomcat 7+ heavily relies on SecureRandom class to provide random values for its session ids and in other places. Depending on your JRE it can cause delays during startup if entropy source that is used to initialize SecureRandom is short of entropy. You will see warning in the logs when this happens, e.g.:
<DATE> org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [5172] milliseconds.

There is a way to configure JRE to use a non-blocking entropy source by setting the following system property: -Djava.security.egd=file:/dev/./urandom

Note the "/./" characters in the value. They are needed to work around known JRE bug #6202721.


CategoryFAQ

  • No labels