tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: cpu 100% java
Date Tue, 01 Aug 2006 21:55:02 GMT
Ben,

> I'm on OS X 10.4.7 running with weblog software (blojsom)
> I have to do a kill -9 on java to stop it from using 100+ on cpu
> sometimes, to let users connect.

I assume that you also have to restart Tomcat at this point, yes?

> This comes up over and over in the log:
> 2006-08-01 17:22:08 StandardWrapperValve[blojsom]: Servlet.service() for
> servlet blojsom threw exception
> javax.servlet.ServletException: Servlet execution threw an exception

[snip]

> ----- Root Cause -----
> java.lang.OutOfMemoryError: Java heap space

You done run outta memory. Since this question ("why did I run out of
memory") comes up a lot, I'll save you some time going through the
gauntlet of one-off responses you are likely to get:

1. Contact the vendor or read their documentation to find out how
   much memory they recommend for the application (taking into account
   the number of users, etc.) and check to see that you have your JVM
   configured have that much memory. If they recommend 128MB and you
   have 16MB configured, then you might just be running out of memory.

2. If you are meeting the vendor's suggestions for memory usage, but
   you think that you have an unusual load (number of users, frequency
   or requests, whatever), then consider increasing your memory
   /somewhat/ to cover that load. Generally, you don't need to go
   allocating 4GB of heap space right away... if you do that, you're
   more likely to put the problem off than anything else.

3. There might be a memory leak. Since you are getting 100% CPU use,
   you might have found a problem with the software getting it into
   a tight and infinite loop (or, at least sufficiently many iterations
   that it may as well be infinite) that generates loads of objects:
   hence, your memory exhaustion. Make sure you have the latest patches
   from the vendor.

4. If you added any of your own code, check that out.
   If you are using a weird JDBC driver, check to see that you have
   the latest compatible version. In fact, check all your libraries.

After that, it's just a matter of changing your memory settings. How you
do that depends on your deployment, but generally you set the
environment variable JAVA_OPTS and use the "-X" parameters to set the
Java heap size.

Often, it helps to set the initial and maximum heap sizes to the same
thing, so that the memory manager never has to grow the heap during the
life of the process -- that can save time and avoid OOMs if Java demands
too much memory too fast (I really hope this is fixed in recent versions
of the JVM... this used to happen and it really should not).

Hope that helps,

-chris



Mime
View raw message