You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Apache Wiki <wi...@apache.org> on 2014/02/02 21:26:51 UTC

[Tomcat Wiki] Update of "HowTo/FasterStartUp" by KonstantinKolinko

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=19&rev2=20

Comment:
Rephrase

  = 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.
+ This section provides several recommendations on how to make your web application and Tomcat as a whole to start up faster.
  
- The Servlet 3.0 specification introduces support for
+ 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.
  
+ == JAR scanning ==
+ 
+ The [[Specifications|Servlet 3.0 specification]] (chapter 8) introduces 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.
+ 
+ For further talk, the features that require scanning are:
+ 
+ Introduced by Servlet 3.0:
+ 
-  *  `javax.servlet.ServletContainerInitializer` (shortened as SCI)
+  *  SCI (`javax.servlet.ServletContainerInitializer`)
   *  Web fragments (`META-INF/web-fragment.xml`)
+  *  Resources of a web application bundled in jar files (`META-INF/resources/*`)
-  *  Using annotations to define components of a web application (Servlets etc.)
+  *  Annotations that define components of a web application (@WebServlet etc.)
+  *  Annotations that define components for 3-rd party libraries initialized by an SCI (arbitrary annotations that are defined in `@HandlesTypes` annotation on a SCI class)
-  *  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.
+ Older features, from earlier versions specifications:
  
- 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.
+  *  TLD scanning, (Discovery of tag libraries. That is scanning for Tag Library Descriptor files, `META-INF/**/*.tld`).
  
- 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.
+ Among the scans the annotation scanning is the slowest. That is because each class file (except ones in ignored JARs) has to be read and parsed looking for annotations in it.
  
- Other features that require scanning are:
+ ''A note on TLD scanning'': In Tomcat 7 and earlier the TLD scanning happens twice,
  
-  *  Discovery of tag libraries. That is scanning for Tag Library Descriptor files (`META-INF/**/*.tld`) (shortened as TLD scanning)
+  * first, at startup time, to discover listeners declared in tld files (done by `TldConfig` class),
+  * second, by JSP engine when generating java code for a JSP page (done by `TldLocationsCache`).
  
- The TLD scanning is done at startup, because a library can define a `Listener` in its TLD file.
+ The second scanning is more noticeable, because it prints a diagnostic message about scanned JARs that contained no TLDs. In Tomcat 8 the TLD scanning happens only once at startup time (in `JasperInitializer`).
  
- A note: in Tomcat 7 and earlier the TLD scanning happens twice, (1) by servlet engine to discover the listeners, (2) by JSP engine when compiling a JSP page. The first scanning happens at startup time (in `TldConfig`), the second one happens when Tomcat needs to compile a JSP page (in `TldLocationsCache`). The second scanning is more noticeable, because it prints a diagnostic message about scanned JARs that contained no TLDs. In Tomcat 8 the TLD scanning happens only once at startup time (in `JasperInitializer`).
+ === Configure your web application ===
  
+ See chapter in [[http://tomcat.apache.org/migration-7.html#Annotation_scanning|Tomcat 7 migration guide]].
- 
- == 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:
  
@@ -49, +51 @@

  
  Scanning for web application resources and TLD scanning are not affected by these options.
  
- See also a chapter in [[http://tomcat.apache.org/migration-7.html#Annotation_scanning|Tomcat 7 migration guide]].
  
+ === 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]].
+ 
- == Exclude JARs from scanning ==
+ === 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.
  
@@ -84, +91 @@

  
  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 ==
+ == Web application ==
  
-  1.  Remove any webapps you don't need. (So remove the all the webapps installed with tomcat)
+  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)
  
  ----

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