Add several Tomcat 7 tips to speed Tomcat start up
|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?
- 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.
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.
- Tweak memory parameters - Google is your friend.
- Trim the config files as much as possible. XML parsing is not cheap. The less there is to parse - the faster things will go.
- Make sure your code is not doing slow things. (Use a profiler)
- Remove any webapps you don't need. (So remove the all the webapps installed with tomcat)
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
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.
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  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".