Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tomcat Wiki" for change 
notification.

The "HowTo/FasterStartUp" page has been changed by KonstantinKolinko:
https://wiki.apache.org/tomcat/HowTo/FasterStartUp?action=diff&rev1=15&rev2=16

Comment:
Rework. Add introduction. Describe options to counter annotation scanning etc.

  = How do I make Tomcat startup faster? =
  
+ This section provides several recommendations on how to make your web 
application and 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 
[[FAQ/Troubleshooting_and_Diagnostics|Troubleshooting and Diagnostics]] page 
for details.
- == 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.
  
+ The Servlet 3.0 specification introduces support for
- == Memory ==
-  1.  Tweak memory parameters - Google is your friend.
  
+  *  `javax.servlet.ServletContainerInitializer` (shortened as SCI)
+  *  Web fragments (`META-INF/web-fragment.xml`)
+  *  Using annotations to define components of a web application (Servlets 
etc.)
+  *  Using annotations to define components processed by an SCI 
(`@HandlesTypes` annotation on a SCI)
+  *  Packing web application resources in jar files (`META-INF/resources/*`)
  
+ These features are collectively referred as "plugability features" and are 
there to simplify plugging of additional frameworks into a web application. See 
chapter 8 of Servlet 3.0 specification for details.
- == 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 ==
+ These features require scanning the JAR files. The worst is scanning for 
annotated classes. There are a lot of class files to process and parsing a 
class file takes noticeable time.
  
+ It is possible to configure a web application to omit most of the scanning. 
It is also possible to configure which JARs Tomcat should skip in its scanning.
-  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 ==
+ Other features that require scanning are:
  
-  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.
+  *  Discovery of tag libraries (`META-INF/**/*.tld`) (shortened as TLD 
scanning)
+ 
+ The TLD scanning happens when Tomcat needs to compile a JSP page. It does not 
affect the startup time, but does affect the access time for the first 
not-yet-compiled JSP page in the web application.
+ 
+ == Remove unnecessary JARs ==
+ 
+ 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 
[[http://stackoverflow.com/questions/1031695/how-to-exclude-jars-generated-by-maven-war-plugin|
 stackoverflow page]].
+ 
+ == Configure your web application ==
+ 
+ There are two options that can be specified in your `WEB-INF/web.xml` file:
+ 
+  1. `metadata-complete="true"` attribute on the `<web-app>` element.
+  2. an empty `<absolute-ordering />` element.
+ 
+ "`metadata-complete="true"`" disables scanning your web application and its 
libraries for classes that use annotations to define components of a web 
application (Servlets etc.). This option is not enough to disable all of 
annotation scanning. If there is a SCI with a @HandlesTypes annotation, Tomcat 
has to scan your application for classes that use annotations or interfaces 
specified in that @HandlesTypes annotation and provide the list of such classes 
to the SCI.
+ 
+ An example of such SCI is in the WebSocket API implementation jar 
(`tomcat-websocket.jar`, `tomcat7-websocket.jar`) which is included with Tomcat 
7 starting with 7.0.47.
+ 
+ The "`<absolute-ordering>`" element specifies which web fragment JARs 
(according to the names in their `WEB-INF/web-fragment.xml` files) have to be 
scanned for SCIs, fragments and annotations. If you specify an empty 
"`<absolute-ordering/>`" it means that none of that scanning will occur. This 
feature does not affect scanning for web application resources.
+ 
+ == Exclude JARs from scanning ==
+ 
+ In Tomcat 7 JAR files can be excluded from scanning by listing their names or 
name patterns in a 
[[http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html#JAR_Scanning|system
 property]]. Those are usually configured in the `conf/catalina.properties` 
file.
+ 
+ In Tomcat 8 you can use a 
[[http://tomcat.apache.org/tomcat-8.0-doc/config/systemprops.html#JAR_Scanning|system
 property]] or configure a `<JanScanFilter>` 
[[http://tomcat.apache.org/tomcat-8.0-doc/config/jar-scan-filter.html| 
element]] in the 
[[http://tomcat.apache.org/tomcat-8.0-doc/config/context.html|context file]] of 
your web application.
  
  == 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.:
+ 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`
+ 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 [[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6202721|JRE bug 
#6202721]].
+ Note the "`/./`" characters in the value. They are needed to work around 
known [[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6202721|Oracle 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".
+ 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".
+ 
+ == 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.
+ 
+ == 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.
+ 
+ == Webapp ==
+ 
+  1.  Remove any webapps you don't need. (So remove the all the webapps 
installed with tomcat)
+  2.  Make sure your code is not doing slow things. (Use a profiler)
+ 
  ----
  [[CategoryFAQ]]
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to