Tomcat & Apache: High CPU Usage

Summary: Tomcat running behing an Apache Frontend Server can cause high CPU Usage on the Java Process. Here are several approaches how to fix it.


Setup: Debian GNU/Linux, Java Runtime Environment (JRE) 1.6, Apache 2.2, Tomcat 6.0.29, mod_jk/mod_proxy


Effect: Accessing web applications directly through Tomcat doesn’t cause any problems. When accessing web applications through the Apache Frontend Server (forwarding requests by using mod_proxy), it took a few seconds and the cpu usage of the Java process went up to 99.9 %. Obviously, the combination of Apache and Tomcat is causing this problem.

Fix: There are several approaches that could help to fix the issue:

  1. Make sure you’re using a newer version of the APR Tomcat Native Library than 1.1.4. See: https://issues.apache.org/bugzilla/show_bug.cgi?id=40909
  2. If you’re using mod_proxy to forward requests from Apache to Tomcat, switch to mod_jk. It is more mature than mod_proxy, although mod_proxy is sometimes consideres to be the successor of mod_jk. For a comparison of both, see: http://community.jboss.org/blogs/mladen.turk/2007/07/16/comparing-modproxy-and-modjk
  3. What finally solved the issue for me: Set a Connection Timeout for the AJP Connector in Tomcat’s server.xml (see http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html). Here is an example:
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" enableLookups="false" keepAliveTimeout="20000" executor="default" connectionTimeout="5000"/>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>