This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Optimizing tomcat5 to run with less memory on a small VDS server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Optimizing tomcat5 to run with less memory on a small VDS server" Watch "Optimizing tomcat5 to run with less memory on a small VDS server" New topic
Author

Optimizing tomcat5 to run with less memory on a small VDS server

Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
I've been getting into Java lately and everything I've done has been on my own computer. Yesterday I decided it was about time I got a servlet container installed and running on one of my spare IPs on my VDS.
Before I installed tomcat5 on my little Etch server which has just 128MB RAM and a slice of a 3GHz CPU I was running with plenty of spare memory and 0.00 load average. That's for Exim4, Dovecot, Apache2/PHP5, MySQL5.
I already had these pimped to run as best I could make them run on low end hardware.

Now when I installed tomcat5 I never though much of it until this morning I SSH'd to my VDS and OMG it was slow. Looking at what was running in "top", the load average was at 0.9 and memory was basically running from swap space

I've had a read around but haven't found a great deal of information on dealing with this so I made some educated guesses modifying server.xml. I brought down min-proccessors and max-processors to values between 2 and 8 as opposed the their default 5-75 values.
I also disabled lookups. Now my load average is back at 0.00 (ish) and I can hammer the server with requests no problem... but my memory is still consumed by the JVM



Does anyone have any tips on getting this down a little bit? 33% of my entire memory being used when no requests are even being made to the servlet container is, well, just a waste really

Eek! I'd better change tomcat so it's running as root 8O

EDIT | Got rid of GDM, Gnome-***??? WTF, X-whatever blah blah. I only moved to this server a few weeks back and never noticed how much crap comes pre-installed on it! It's supposed to be a basic debian etch server... not desktop. Grrr!!

[ August 24, 2007: Message edited by: Chris Corbyn ]

[ August 24, 2007: Message edited by: Chris Corbyn ]

[ August 24, 2007: Message edited by: Chris Corbyn ]
[ August 24, 2007: Message edited by: Chris Corbyn ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The first thing to remember is that Tomcat is a Java application and all Java applications, no matter how small or large, need to run in a Java Virtual Machine (JVM). There is a certain amount of memory needed to run a JVM.
Also, Tomcat was written to run on servers. It was optimized to scale up, not down. It actually does a decent job scaling down (for Java server software) and is often used as an embedded component in IDEs but is optimized to run web applications on server class machines.

All that being said, look up the -Xms and -Xmx heap memory switches.
You set them in the JAVA_OPTS variable at the top of your catalina.sh script in the TOMCAT_INSTALL/bin directory. You can probably bring it down a bit with those.

You might also want to get rid of the applications that ship with Tomcat.
The manager app is handy to have around (especially for verifying that your Xms and Xms settings took) but if your goal is to shave off as much as possible, get rid of it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Chris, if you wouldn't mind, could you edit your first post and narrow the lines in your top screen?
They're stretching this entire thread, making it hard to read.
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Thanks Ben, I'll have a play. At least I have an idea what to look for. I'd love a better server but my wallet can't justify it for open source projects I make barely any money from

Original post editted... sorry about that, I hadn't noticed the long lines
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Understood.

You might also want to look at Jetty.
I've heard that it's a bit smaller than Tomcat.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Chris Corbyn:

Original post editted... sorry about that, I hadn't noticed the long lines


That looks much better. Thanks.
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
I've changed the JAVA_OPTS to use -Xms8M and -Xmx32M (it was 128M by default, which is my entire system memory) and it doesn't appear to have changed anything really (a marginal amount more in swap space and a slightly lower hardware resource usage, but not much).

Getting the load average down seems to have resolved my slowdown and with the memory I have left it doesn't appear to be slow at the moment so I may just monitor it.

I was planning on looking around other containers to find something a bit lighter so thanks for the tip on Jetty
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Just a quick update to put some closure to this one. The heap values didn't appear to make an immediate difference but after leaving the container up and running for a short while to memory usage seems to peter out and lingers at around 15-20% (~10-20MB) which is therebaouts what I have set.

I also tweaked MySQL and removed spamassassin because that was just about as resource intensive as Java even when sitting idle. I've got DSPAM installed now and its memory footprint is next to nothing so my server is running at a comfortabe load
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Optimizing tomcat5 to run with less memory on a small VDS server