File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Advanced performance adjustments for Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Advanced performance adjustments for Tomcat" Watch "Advanced performance adjustments for Tomcat" New topic
Author

Advanced performance adjustments for Tomcat

Mat Banik
Ranch Hand

Joined: Jan 16, 2004
Posts: 57

Hi Everyone,

I'd like to find out if there is process that would allow for guaranteed performance tuneup for Tomcat server.

The only viable parameters I found to be useful to adjust are:
Initial memory pool size in MB
Maximum memory pool size in MB
Thread stack size in KB

I check the status here:
http://localhost/manager/status

And I'm trying to bite my way through this doc:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

I found that playing with these parameters is resulting in changes in performance when I do load testing:

-Xms256m -Xmx1024m -XX:NewSize=128m -XX:MaxNewSize=128m -XX:SurvivorRatio

I actually never set Thread stack but this is what I found out about it:
Deep recursive algorithms can also lead to Out Of Memory problems. In this case, the only fixes are increasing the thread stack size (-Xss), or refactoring the algorithms to reduce the depth, or the local data size per call.
I believe that someone suggested 1024KB but I could not start the server with that size.

Any tips hints and suggestions would be greatly appreciated.



SCJP 1.4 - 83%, SCJD 360-90%,
ITeezy.com
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm not sure what you mean by "guaranteed performance tuneup".
Tomcat's defaults, for the most part, are set for production. Most of the changes I make slow things down but make more friendly for production (reloadable, logging etc...).

The memory changes that you mentioned are less Tomcat specific and more JVM specific. If you want to learn how to tweak the JVM, you might want to try some google searches that don't include Tomcat.
This was my first find when I googled "Java JVM Tuning"

http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tprf_tunejvm.html

Are you having a specific performance issue that you're trying to address?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mat Banik
Ranch Hand

Joined: Jan 16, 2004
Posts: 57

I run Spring app server and every time I reach 10000 active connections the server runs out of resources and requires reboot. I have been able to work around the issue by setting limits on the applications being run.
I don't know how to cross 1024 maximum memory limit. I can pup up the server with 16GB of ram and since it is on the cloud the processors would be no issue either but I don't know enough about tomcat or more precisely JVM to go start tuning this out.
There for I'm looking for some sources to start learning about it. Including spreading the View-Model processing on several Tomcat instances.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Tomcat can be clustered.
There is good documentation on their site for this.
http://tomcat.apache.org

I've read that the 1024 M limit is due to 32 bit OSes can't give more than 1024 megs of contiguous blocks of ram to a single application and that JVMs require contiguous blocks. I don't know whether this a Windows OS thing or if it's an Intel chip thing.
If it's the latter, switching to Linux wouldn't help. The fix, I've read, is to upgrade to a 64bit system.

I'm hitting the 1024 ceiling myself. I'm looking at a couple options. One is to upgrade hardware to have a 64 bit system.
I'm also toying with the idea of taking some of the more memory intensive operations (PDF merging and creation, for example) and forking a new process for them. Tomcat give you the option to do this with JSP compilation.
Mat Banik
Ranch Hand

Joined: Jan 16, 2004
Posts: 57

I run dev server on Windows 2003 32bit and production on CentOS 64bit. But I can't mess around with production too much. So I'm trying to pool some info first and develop trial and error plan.

I don't know how this:
http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

would work with Spring framework. I heard about Terracotta but I'm not sure how that would work since I haven't even seen clustered tomcat or spring yet.

I don't use much JSP. I'm running the front-end on sitemash and freemarker.
I would imagine there would be some problems with application context. I'm running most of the pages stateless but some are statefull and that could be a problem.
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Matej,

It would help greatly if you posted the stack traces that you find in the logs before the reboots. Without those we do not know what resources Tomcat runs out of and tuning is pointless.

There are no "guaranteed performance tuneup" for any app server. It all depends on what you make that app server do.

Post stack traces.

Kees Jan


Java-monitor, JVM monitoring made easy <- right here on Java Ranch
Mat Banik
Ranch Hand

Joined: Jan 16, 2004
Posts: 57

The logs are standard vanilla stuff about Catalina not having enough memory.
I will install 64 bit system so I can test the JVM with more memory allocation.
Did anyone try to run tomcat with 16GB of ram on 64 bit system?
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Matej,

Please note that there are a dozen or so forms of OOME's. Please post the message part of the exception, so we can see what happend precisely.

We routinely run with 6 GB heaps. No problem.

Kees Jan
Mat Banik
Ranch Hand

Joined: Jan 16, 2004
Posts: 57

Hi Kees Jan,

I have no idea what OOME means. If you have link to at least one forum that is in your opinion good I would appreciate it.

Every-once in while I get java.lang.OutOfMemoryError: Java heap space.
I tweak the heap sizes around with garbage collector every time and it is good after that for a while. But there is only as much you can do on 32 bit JVM.

I'm trying to find out if I can run 64 bit CentOS with JVM (JDK 6.0) that is 64bit. But I fount out that it will be problem with intel processors. The AMD once seem to be the only processors that will work with 64bit JDK 6.0.

At this point it seems that I should open post on 64bit JDK.

Are you running it on your own server or do you have dedicated hosting or do you run on cloud space?

Mat
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Matej,

OOME is short for OutOfMemoryError.

The Saloon on Javaranch is a great forum. Probably the best. I like http://java-monitor.com/forum/ too, but I am biased, since I operate that forum. ;-)

The error you posted confirms this is a heap space issue and not something else.

I run JDK 1.6 in 64-bit mode on both AMD and intel processors. It just works. I have my own hardware.

I would suggest you also make heap dumps and use profiling to try to reduce the memory footprint of your application. That will give you more time to buy hardware.

Kees Jan
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16313
    
  23

Kees Jan Koster wrote:Dear Matej,

OOME is short for OutOfMemoryError.

The Saloon on Javaranch is a great forum. Probably the best. I like http://java-monitor.com/forum/ too, but I am biased, since I operate that forum. ;-)

The error you posted confirms this is a heap space issue and not something else.

I run JDK 1.6 in 64-bit mode on both AMD and intel processors. It just works. I have my own hardware.

I would suggest you also make heap dumps and use profiling to try to reduce the memory footprint of your application. That will give you more time to buy hardware.

Kees Jan


Gotta admit I was scratching my head about "OOME" myself. I have enough trouble with NPE.

Getting good stack info is critical. I lost nearly a month of my life on a, ahem, OOME that was only reproducible by allowing the system to run for 3-5 days. Turned out to be a "cache" that didn't understand that part of the difference between a cache and a bottomless pit is that a cache is expected to have a limit beyond which it starts discarding stuff.

The worst thing was, this "cache" was from a major vendor, who had even explicitly documented its lack of a discard mechanism. But not very well.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advanced performance adjustments for Tomcat