Differences between revisions 14 and 15
Revision 14 as of 2012-03-22 12:56:50
Size: 2487
Editor: 81
Comment: Add several Tomcat 7 tips to speed Tomcat start up
Revision 15 as of 2013-07-12 19:48:49
Size: 2804
Editor: 69
Comment:
Deletions are marked like this. Additions are marked like this.
Line 36: Line 36:
 Also note that replacing the blocking entropy source (/dev/random) with a non-blocking one actually reduces security because you are getting less-random data. If you have a problem generating entropy on your server (which is common), consider looking into entropy-generating hardware products such as "EntropyKey".

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.

    Also note that replacing the blocking entropy source (/dev/random) with a non-blocking one actually reduces security because you are getting less-random data. If you have a problem generating entropy on your server (which is common), consider looking into entropy-generating hardware products such as "EntropyKey".


CategoryFAQ

HowTo/FasterStartUp (last edited 2014-10-18 01:15:33 by 81)