18 Java Tomcat Application Optimization Tips

Tomcat. It’s more than that cute little figure above. 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.

Now, we all know that the Internet is a great resource for information. But it is sometimes too much to wade through hundreds of web pages looking for tips about Tomcat performance.  So Monitis has done it for you! Below are some of the more useful tips found in various places on the Internet.

 

 

Tip #1 – Precompile 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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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

Tip #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/

Tip #16 – Beware of Redeployment Memory 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/

Tip #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.

http://blogs.mulesoft.org/tomcat-performance-tuning-tips/

Tip #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.

http://blogs.mulesoft.org/tomcat-performance-tuning-tips/

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