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).