tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: Checking Tomcat's Memory
Date Thu, 15 Aug 2002 17:19:08 GMT

>CATALINA_OPTS=-server -Xms1g -Xmx3g
>and from reading previous e-mails on this list, this should set the JVM
>and max heap size, yet how can I verify this?

That's the correct way to set them.  

Here's a simple way to verify things, as I inherently distrust Windows
performance monitoring tools:

- Write a very simple app that would allocate roughly 1 GB of RAM.  For
example, by creating a 1000000 * 1000 array of Integer objects.

Integer[][] hugeArray = new Integer[1000000][1000];
for(l = 0; l < 1000000; l++)
  for(l2 = 0; l2 < 1000; l2++)
    hugeArray[l][l2] = new Integer(l2);

- Start the server with this app running, but not your other apps.
(Assuming ROOT, examples, tomcat-docs etc take very little runtime
memory).  Make sure you trigger the above code, and see that it runs
without an OutOfMemoryError.  You've just verified the minimum setting.

- Modify the above code to 3000000 * 1000, again run it, verify that it
*does* generate an OutOfMemoryError.  Then you will have verified the
-Xmx setting.

- Obviously, I used perfectly nice round numbers in the above code.  Due
to internal tomcat stuff, other webapps, runtime overhead, JVM overhead,
etc, the actual numbers will be lower.

- You can also verify within the program how much RAM hugeArray took up
by trying something like:

	long memBefore = Runtime.getRuntime().totalMemory();
      hugeArray = null;
	long memAfter = Runtime.getRuntime().totalMemory();
      long hugeArrayMemory = memAfter - memBefore;

- As always, stuff like the above should be run several times and
averaged, for a more reliable predictor.  System.gc() is not guaranteed
to run, much less do a full GC, etc etc  I assume you already know all
about that.

Maybe this will help ;)

You can also try MemoryMonitor from these guys:

I've used it in the past, it's decent.  But I trust the above approach

Yoav Shapira
Millennium ChemInformatics

>I'm currently testing a program that takes a considerable amount of
>and after getting so many thousand requests (and storing a considerable
>amount of data in memory), the performance becomes horrible (3 to 4
>CPU usage, possibly due to gc looking for more memory?).  I suspect the
>memory settings because when the CPU usage starts to spike, the memory
>tops off and does not appear to go up at all (when it most likely
>continue to go up).
>Suggestions appreciated!
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>For additional commands, e-mail: <mailto:tomcat-user-

View raw message