Tomcat – Varnish + Tomcat vs Apache + mod_jk + Tomcat

apache-2.2mod-cachemod-jktomcatvarnish

Does anyone have some performance metrics for Varnish in front of 1) Tomcat or 2) Apache with mod_jk (connected to Tomcat). I know that the AJP connector is supposedly faster than HTTP, but I was thinking that Varnish which is lighter and highly optimized could perform better talking direcly to Tomcat.
There is also the discussion around static resources (which I think will perform faster with Varnish than Apache, even with mod_cache) and dynamic pages.

Best Answer

Generally Varnish can deliver a cache hit several orders of magnitude faster than Tomcat - typically TTFB is microseconds for Varnish and milliseconds for Tomcat. So, the performance of the connector (AJP vs HTTP) probably won't matter when Varnish is involved. So, go for the simpler setup - have Tomcat speak directly to Varnish. The marginal effect AJP might have will be completely insignificant.

If you are considering not having Varnish there at all I think the question you should be asking yourself is what the hit rate for the dynamic pages from Tomcat will be. If it is >20% then I think the overall performance increase might be worth the extra complexity, depending on how heavy the pages are.