I got a request from a client for performance-tuning Tomcat. Typically, I don’t really do a lot performance tuning for Tomcat - usually, I front it with Apache HTTPD, and spend most of my performance tuning efforts on the application, not the server.

I got thinking about it, though, and remembered that there is a “native” Connector for Tomcat, so I decided to do an informal benchmark to see how dramatic the difference is.

First, the caveats - the benchmark was extremely informal, and I did it on my laptop, which was the same machine that was running Tomcat. Your mileage will certainly vary…

I set up a simple JMeter test to launch 100 concurrent threads against Tomcat’s examples/jsp/xml/xml.jsp page, with a ramp-up time of 1 second, and to loop 10 times. So, 1000 requests by 100 concurrent users.

This was done on Ubuntu 9.04 “Jaunty”, with Tomcat 6.0.20 and tomcat-tcnative-1.1.16 on a Dell Vostro 1500 with an Intel Centrino Duo 2.4GHz cpu  and 4Gb of memory. I ran each test several times, to make sure that the JSP was compiled, and that the server was “warmed up”.

To my great surprise, the default, all-Java Tomcat installation was faster than with the addition of the native code. It may be that when both are fine-tuned, and under heavy real-world loads, the native code may scale better, but this does leave me wondering.

Here’s the results from JMeter (all times are in milliseconds):

Avg Median 90% Min Max
Java 2 1 6 6 47
Native 33 12 80 0 561

That looks like an order of magnitude difference to me.

This just goes to prove the wisdom of the advice to measure before optimizing.