Main Content

Apache httpd to Tomcat - jk v proxy

Archive - Originally posted on "The Horse's Mouth" - 2006-03-03 13:35:28 - Graham Ellis

Many of our customers run both the Apache httpd and Apache Tomcat web servers - with good cause, since Tomcat is biased towards web applications where the same code is run many, many times over and httpd is biased towards serving pages and is better tuned for a much larger number of different pages but at a somewhat less frequent interval.

But the user (via browser) wants a single point of contact - typically httpd - with a number of mechanisms used to link the two servers. Jserv, mod_jk2 and warp are all deprecated, mod_rewrite can be used, but the most common link is done through httpd's mod_jk or mod_proxy modules. Historically, mod_proxy has been much easier to set up but has had a reputation for being much slower. Link - "The Connector Story"

Is mod_proxy's reputation for being slow deserved? How DO the speeds compare? The questions were asked during last week's deployment course in Glasgow and I thought I would - my first clear day - do some experiments to find out.

I set up a server (Linux, Fedora core 3, Apache 2, Tomcat 5.5) and set up both jk and proxy connections between them. I also set up an httpd alias to allow a direct httpd access to a web application, and an http connector on Tomcat to allow direct access via that server. I then benchmarked a plain HTML file of 1k in size, using the ab tool to load the page 1000 times in quick succession in four different ways.

ab -n1000 http://snowdrop:8080/latmjdemo/index.html > tomcat
ab -n1000 http://snowdrop/direct/index.html > httpd
ab -n1000 http://snowdrop/latmjdemo/index.html > jk
ab -n1000 http://snowdrop/felix/index.html > proxy

Running the test on a quiet network five times, with the ab commands running in a different order to balance out any caching issues, I got the following:

Direct access via httpd - 300 per second
Direct access via Tomcat - 483 per second
Access via both servers connected by jk - 307 per second
Access via both servers connected by proxy - 222 per second

What I expected? No, to be honest I was surprised that the direct access via httpd was so slow compared to the others. But then thinking it through, Tomcat is a great CACHEING server so it will perform proportionately far better on a test such as this that repeatedly hits the same page.

I was also pleasantly surprised to see that proxy was less that 30% slower than jk - I feared much worse. And thinking through the benchmark I ran, serving an html page is likely to be one of the data types that shows up the difference too - there's no gobs of Java code to be run to dilute the protocol time.

Conclusion? If you want every ounce of performance from your httpd / Tomcat pair, use jk. If you're not pushing it to the limit, then proxy's likely to be fine for you.