18 Java Tomcat Application Optimization Tips

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies. This servlet container software powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations.

 

 

 

transaction monitoring

 

1. Pre-compile Java Server Pages

Precompile Java Server Pages (JSP) whenever possible.  This is the main JSP optimization, but it is not always possible to do this.

http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html

2. Set Development to “False”

When using Jasper 2 in a production Tomcat server, set development to “false.”  Set it to “true” in the development environment.  One caveat: Sometimes this cannot be done, for example, with dynamic generation of JSPs.

http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html

3. Set genStringAsCharArray to “True”

When using Jasper 2 in a production Tomcat server, set genStringAsCharArray to “true” to produce more efficient char arrays.

http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html

4. Set modificationTestInterval Higher

When using Jasper 2 in a production Tomcat server where development has been set to true, set modificationTestInterval to a higher value.  This may impact performance significantly.

http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html

5. Set trimSpaces to “True”

When using Jasper 2 in a production Tomcat server, set trimSpaces to “true” to remove useless bytes from the response.

http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html

6. Replace Dynamic Pages With Static Pages

If a dynamic page rarely changes, design it as a static page instead.  Regenerate the static page on a regular basis or as needed.

http://javahelp123.blogspot.com/2008/12/tomcat-performance-tuning.html

7. Cache Pages

Cache both static and dynamic pages if this will not create a security concern and if the application design allows it.

http://javahelp123.blogspot.com/2008/12/tomcat-performance-tuning.html

8. Use a Profiler

Use a profiler (e.g., JProbe, JProfiler) during development to see where the CPU, memory, network connections and external storage are most heavily used in your application.  Look for a more efficient redesign of the sections with the heaviest usage.

http://javahelp123.blogspot.com/2008/12/tomcat-performance-tuning.html

9. Find the Bottlenecks

Look for thread synchronization bottlenecks, especially stopgaps of date and time threads.

http://javahelp123.blogspot.com/2008/12/tomcat-performance-tuning.html

10. Understand the Application’s Connection Usage Patterns

Connections are costly.  Whether you’re talking about HTTP transactions, server-side includes, TCP connections, or the HTTP Keep-Alive setting, be aware that each and every connection affects performance.  Reducing the number of connections improves performance, but you can’t fully do that if you don’t understand how and when the application connects to the outside world.

http://thegeekhead.blogspot.com/2009/06/important-but-ignored-performance-tips.html

11. Use Connection Pooling

Use connection pooling to reuse connections rather than closing and reopening them.

http://thegeekhead.blogspot.com/2009/06/important-but-ignored-performance-tips.html

12. Set an Appropriate Maximum for Number of Threads Per Connector

Typically, connectors use 200 to 800 threads efficiently, but the best number depends on your application and the host that it runs on.  If CPU usage is high, reduce this value.  Consider the impact your choice will have on other applications, too.

http://thegeekhead.blogspot.com/2009/06/important-but-ignored-performance-tips.html

13. Set an Appropriate Value for maxKeepAliveRequests

The maximum number of HTTP requests per TCP connection (maxKeepAliveRequests) defaults to 100 in Apache.  In production, a higher value (e.g., 1,000) often provides better performance.  A value of zero allows unlimited requests. Curious to read more on this topic?

http://thegeekhead.blogspot.com/2009/06/important-but-ignored-performance-tips.html

14. Set Timeout and KeepAliveTimeout As Low As Possible

The Apache Timeout and KeepAliveTimeout directives should be set as low as your production environment will tolerate for maximum performance.

http://thegeekhead.blogspot.com/2009/06/important-but-ignored-performance-tips.html

15. Identify Memory Leaks

Tomcat memory leaks are most easily identified by using a commercial or free profiler.  Recent Sun JDKs contain some helpful tools, for example, jmap and jhat).  YourKit is helpful, and it offers a free license to open source developers.

http://blog.springsource.com/2008/10/14/optimising-and-tuning-apache-tomcat-part-2/

16. Beware of Redeployment Leaks

Redeployment can cause memory leaks.  If a class is loaded by both Tomcat and the web application, then both have references to the class.  When the web application stops, the Tomcat class loader still has its reference to all the classes it loaded.  As long as references exist, the referenced object is not eligible for garbage collection. Especially watch JDBC drivers and logging frameworks.

http://blog.springsource.com/2008/10/14/optimising-and-tuning-apache-tomcat-part-2/

17. Cache Static Content in the Client Web Browser

The end user’s perception of performance can be greatly enhanced by caching static content. Set the HTTP response headers accordingly when serving the web app’s static files.  Be prepared to put some hours in on this task, but know that the payoff will be worth it.

18. Use HTTP Rather Than HTTPS

Of course, you cannot use HTTP exclusively because HTTPS is essential for secure or confidential data.  However, HTTPS should not be used where it is not necessary because it substantially increases the number of times the client and server send messages over the network.

These tips for Tomcat, like our other series of blog advice and tips on critical and/or frequently used applications, will help you optimize your time.  Who wants to figure out the ins and outs of an application from the get go? Don’t you have more important things to do?

You might also like