HOWTO: Optimize and deploy your Tomcat applications with Excelsior JET
Article ID: 000018
Last Revised On: 26-Sep-2005
PDF Version: 000018.pdf
The information in this article applies to:
- Excelsior JET Professional versions 3.5 MP3 through 3.7
- Apache Tomcat 4.0.x and above
This article does not apply to Excelsior JET 4.0 and above.
SUMMARY
This document contains step-by-step instructions for using Excelsior JET to compile the Apache Tomcat application server along with your deployed web applications. Deployment of the entire system to end users is also covered.
Project files and build/run scripts for this article may be found here.
INTRODUCTION
Today’s state-of-the-art server-side Java applications usually run on a so-called application server. The application server itself is, in turn, a Java application and thus can be converted to an executable using Excelsior JET.
A typical application server, such as Apache Tomcat, loads applications for further execution through server-specific classloading that cannot be defined before the actual server execution. As a result, deployed applications can not be precompiled together with the server, but have to be dynamically compiled during the server run. The Caching JIT compiler, available only in Excelsior JET, Professional Edition, is capable of compiling classes loaded by those server-specific classloaders, and caching the results of compilation to disk. For better performance, you may optimize the accumulated JIT cache after shutting down the server using JIT Cache optimizer.
To sum up, in order to compile a non-standalone server-side Java application with Excelsior JET, you have to perform three major steps:
- Compile the application server engine to an executable. During this step, all jars constituting the engine will be precompiled, so they need not be included in the deployment package.
- Launch the compiled server and put some load on your applications to accumulate the JIT cache.
- Optimize the JIT cache.
Unfortunately, you would still have to include the original application jars in the deployment package, since it can not be guaranteed that all classes of the application were used and thus put in the JIT cache. Moreover, even if some class was compiled and cached, it may happen that it would have to be compiled again.
Why do I need all these
Beside a considerable performance boost, the reason to use Excelsior JET for server-side applications is download size reduction.
The main problem with application servers is that they should be run on a JDK, not JRE in order to be able to compile JSPs. So the all-inclusive download package should contain a copy of the JDK that alone may weight more than the rest of the package. On the other hand, since server-side applications usually do not use AWT/Swing, a JET-compiled package may not include any JDK or JRE. Thus, the download size can be reduced by a factor of 2 (or about).
DETAILS
We shall illustrate the process of optimizing and deploying an application server with some applications using Apache Tomcat as an example.
- First of all, you configure the Tomcat server in the way you want it to be deployed in the production environment. That is, you deploy your web application(s) to the Tomcat server. Optionally, you may also wish to undeploy the samples coming with the original Tomcat distribution.
- You create a new JET Profile with Endorsed Standards Override using JET Setup (endorsed jars come with Tomcat in <Tomcat>/common/endorsed" directory) as follows:
- Launch JET Setup and initiate the creation of a new profile. On the Choose JRE page, check the Override endorsed APIs checkbox:
- On the Choose overriding jars page, select Specify the "java.endorsed.dirs" property" and type the full path to the Tomcat endorsed jars directory in the respective field:
- Unzip 000018.zip to the Tomcat installation directory on your machine. This will create a subdirectory called jetbuild with some files in it. Set it as the current directory.
- If you are specifying extra VM properties in Tomcat startup scripts (e.g. the -Dorg.apache.commons.logging.Log property), correct the -tomcatvmprop equation in xtomcat.prj accordingly.
Warning: When correcting the equation do not forget to use ":" instead of "=" as the delimiter between property’s name and value.
- Invoke the build script to compile the Tomcat server. An executable called xtomcat will be created in the jetbuild directory.
- Invoke the run script to launch the JET-compiled Tomcat.
- Now, stress test your application(s) to achieve the largest possible code coverage. Ideally, you should use all features, all modes of operation, and all their combinations on large amounts of heterogeneous input data. After that, stop the Tomcat server by pressing Ctrl-C.
Note however that non-exhaustive testing does not imply that your application will not function properly after JET-compilation. The idea is that thorough testing will result in caching of more classes, which is required for their subsequent optimization on the next Step.
- Invoke the buildwebapps script to create the JET-compiled version of your application(s). A single, optimized binary containing your web application(s) code and a JIT cache descriptor will be created in the directory jetbuild/jittemp. You may then cleanup that directory by removing all the other files and subdirectories, unless you plan to add more applications or classes to the cache before packaging the whole system for deployment.
- Invoke the run script again to make sure your optimized applications work.
- Now, if you need to deploy the optimized applications to other systems, prepare an installation package containing Tomcat and your applications. To do that, launch JetPackII and follow the instructions below.
- Splash screen. Click New.
- Page 1. Click New.
- Page 2. Add files to the installation package as follows:
- From the Filechooser panel, drag the following subdirectories of the Tomcat directory (with their contents) onto the Package Files panel:
common
conf
server
shared
temp
webapps
work
- In the Package Files panel, remove all jars from the following directories:
/common/endorsed
/common/lib
/server/lib
/server/webapps/admin/WEB-INF/lib
/shared/lib
(you may do that because the classes from those jars were precompiled into xtomcat, and resources from those jars were bound to that executable as well.)
- In the Package Files panel, create the bin directory in the root of the package.
- Drag the xtomcat executable from the jetbuild directory in the Filechooser panel to the bin directory you just created. JetPackII will prompt you for automatic inclusion of the existing JIT cache into the installation package:
Click Yes.
- Page 3. For the purposes of this sample, you may skip this page.
- Page 4. Choose "Do not use JRE" and click Ok in the warning box displayed.
- Page 5. Choose required locales.
Important: if you are using Excelsior JET 3.5 and the active JET profile is based on JRE 1.4.x, check "Show all components" and mark the XMIA component /You have to do this due to a bug in Trial Run in JET versions prior to 3.6/ :
- Page 6. Perform Trial Run of xtomcat with the argument string set to “start”:
Test your web application(s), then stop the server by pressing Ctrl-C in the Trial Run console. JetPackII will ask you if the non-zero return code should be ignored. Click Yes.
- Page 7. Select the desired backend and click the Next button.
- Page 8. If you selected the Excelsior Installer backend, create shortcuts for xtomcat executable with desired arguments (the obvious two are “start” and “stop”).
- Page 10. Click Create and find your installation package in the target directory you selected.
Now you can test the resulting installation package on a machine not having J2SE/Tomcat installed.
REFERENCES
- Excelsior JET User’s Guide: http://www.excelsior-usa.com/doc/jc.html, Chapter “Mixed Compilation Model”.
Copyright © 2003-2006 Excelsior LLC. All rights reserved.
|