Friday, October 31, 2008

Apache Versus Tomcat

This is a pretty popular question judging from the results on google,so I just wanted to consolidate whatever information I found on the web,which helped me decide.

Apache Http Server comes with other features like Modules configuration, SSL, SSO capabilities etc .
If you use Apache Tomcat,you are restricted to serving jsp's and servlet's.
Clustering: By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances.so handling the failure of one Tomcat is easier.But you could always use Tomcats Clustering capabilities and a hardware load balancer.Apart from loadbalancing.
Clustering/Security: You can also use Apache as a front door to different Tomcats for different URL namespaces (/app1/, /app2/, /app3/, or virtual hosts). The Tomcats can then be each in a protected area and from a security point of view, you only need to worry about the Apache server. Essentially, Apache becomes a smart proxy server. 2/ (i.e. the capability of reverse proxying, allowing you to 'plug in' one or more web applications running on one or more Tomcat instances in one URL space.)
Security. This topic can sway one either way. Java has the security manager while Apache has a larger mindshare and more tricks with respect to security. But also keep in mind, if you run Apache with Tomcat - you have two systems to defend, not one.
Add-ons. Adding on CGI, perl, PHP is very natural to Apache. Its slower and more of a kludge for Tomcat. Apache also has hundreds of modules that can be plugged in at will.
With Apache in front of Tomcat, you can perform any number of decorators that Tomcat doesn't support or doesn't have the immediate code support.
Speed. Apache is faster at serving static content than Tomcat. But unless you have a high traffic site, this point is useless. But in some scenarios, tomcat can be faster than apache. So benchmark YOUR site. Socket handling/system stability. Apache has better socket handling with respect to error conditions than Tomcat. The main reason is Tomcat must perform all its socket handling via the JVM which needs to be cross platform. The problem is socket optimization is a platform specific ordeal. Most of the time the java code is fine, but when you are also bombarded with dropped connections, invalid packets, invalid requests from invalid IP's, Apache does a better job at dropping these error conditions than JVM based program

No comments: