Tomcat – Apache/Tomcat Parameters

apache-2.2javaload-testingperformancetomcat

I have a Medium server on EC2. I don't know that much about Apache or Tomcat – they are up and running, but other than that I don't have advanced knowledge of how to tinker. I know that I can set the min/max JVM size for the Tomcat Server, and that I can set how many threads Apache can fork off, but I don't know what "reasonable" values for these parameters are.

  1. I realize the answer is subjective, but are there common settings I should start off with?
  2. Is there a simple way to load/performance test my application?

Thanks.

EDIT:

The system is an EC2 Medium:

High-CPU Medium Instance:

  • 1.7 GB of memory
  • 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each)
  • 350 GB of instance storage
  • 32-bit platform
  • I/O Performance: Moderate
  • API name: c1.medium

The only services I am running are Apache and Tomcat. Nothing else is on the server.

Best Answer

Apache

Check out Apache's own documentation, it goes into more detail than I could here:

http://httpd.apache.org/docs/2.0/misc/perf-tuning.html

JVM

Set your JVM's Xmx to no more than 70% (roughly) of the total free physical RAM. The reason for this is that the perm gen and JVM libraries take additional space up too - the aim is that the total process memory will never use virtual / swap memory. If you set this too high, you'll start seeing issues like "GC overhead limit exceeded".

Your GC algorithm can have a big effect on performance - make sure that you're using some form of parallel collector and not the serial 'pause, mark and sweep'. The JVM usually does this for you automically in -server mode.

Use a tool such as JConsole or JVisual VM to inspect the GC and how much heap you're actually using, and adjust down to suit - too large a heap can impact garbage collection times.

Tomcat

As for HTTP connector threads, on a single instance of Tomcat, depending on your application you can usually up the thread count to around 600 before encountering issues - however, there's often no need for it to be quite that high - you'll just be putting more pressure on your CPU and memory.

Once you're happy with the max threads, I then set the minSpareThreads and maxSpareThreads relative to that. Upping the values if I know I'm gonna get hit with spikes in new connections etc.

Next up acceptCount. This is the maximum queued connections -c onnections that spill over this setting after using up the connector threads will receive a "connection refused".

As a minor tweek, you can set enableLookups (allow DNS hostname lookups) to false. When enabled, (slightly) adversely affects performance.

Also, check out the Tomcat Native Library, this uses native code to boost performance in certain operations (like file IO etc).

Load Testing

For basic load / performance testing, check out Apache JMeter:

http://jakarta.apache.org/jmeter/

We use it to test basic page load performance, with JMeter test scripts using hundreds of concurrent requests. You do need a fairly hefty server to run it on though (not on the same machine you're running Apache HTTPD and Tomcat).