Tomcat.exe is consuming 75% of CPU. Is anyone having any idea why it happens and how can that be decreased?
I am using Tomcat5.5 & J2SDK v 1.4.2_12
We just solved a problem with our tomcat instance running with very high cpu usage, swinging up to 100% and more every few seconds and then briefly down again. This occurred all day long and all night long, whether the server was performing any work or not. We are running tomcat 8 with java 8.
We did not find our solution in a web search, so I am posting it here in the hopes of helping someone else.
We had used the configuration option in the tomcat/conf/Catalina/localhost directory, in which we pointed tomcat to another directory, other than its own webapps directory. The xml files in this directory look like this:
<?xml version='1.0'?>
<Context
docBase="/opt/dspace/amaddev/dspace-6.3/webapps/jspui"
reloadable="true"
cachingAllowed="false"/>
And this worked, tomcat ran with the code in these directories rather than its own webapps directory. However, we had this problem with continually spiking cpu usage.
To test, we removed the xml files from the conf/Catalina/localhost directory, and restarted tomcat. Suddenly we had a normal, well-behaved tomcat again. In order to point the tomcat to this other directory (where we compile our dspace code), we just used the Host entry in conf/server.xml, and changed the appBase setting to our dspace directory:
<Host name="localhost" appBase="/opt/dspace/amaddev/dspace-6.3/webapps"
unpackWARs="true" autoDeploy="true">
This now accomplishes what we wanted with a very low cpu usage (below 1%) when the server is quiet.
This is most likely caused by the application(s) that you are running on top of the tomcat. Of course if you have very high traffic on your applications, this could also be the reason.
I recommend to look at the Tomcat log files, especially file called catalina.out. In my case that file was expanding fast with error messages saying "no permissions to read folder /var/lib/mysql". My application includes a watch service that monitors folder /var/lib/mysql. By allowing the application to read this folder the CPU usage came down drastically. High CPU usage appeared after a system update that can change permissions to access folders and files. Thus the reason for high CPU usage can be external to the web application and also external to Tomcat container.
My logs were full of Tomcat logs. I deleted all of them and the CPU usage has gone dramatically down.