Using ProxyPassMatch In Clustering
Donnerstag, 22. Oktober 2009
Building on from the Clustering Railo with Tomcat and Apache article where we set up the Railo Tomcat cluster. The cluster was set up to send all requests on to Tomcat no matter whether needed or not. While in a low traffic site sending every single request to Tomcat for processing may not be a big deal you probably haven’t gone through the trouble of setting up a cluster for a low traffic environment therefore you certainly want to squeeze as much performance out of your available resources. There are a number of ways to do this:
1) You could place a proxy server like nginx in front of Apache to serve all the static files.
2) You could use ProxyPassMatch to tell Apache to send only cfm and cfc requests to Tomcat and let Apache serve the static content.
We are going to do the second option and let Apache handle the static content and pass only the dynamic request on to Tomcat. To do this we will use the ProxyPassMatch Directive which allows us to construct a regular expression and will replace the ProxyPass Directive we used before.
This is how the proxy information in your vhosts.conf file looks like now.
<Proxy balancer://mycluster>
BalancerMember ajp://<your server1 ip>:8009/ route=node1 loadfactor=1
ProxySet lbmethod=byrequests
</Proxy>
ProxyPreserveHost On
ProxyPass / balancer://mycluster/ nofailover=On
And this is what it should look like after using ProxyPassMatch
<Proxy balancer://mycluster>
BalancerMember ajp://<your server1 ip>:8009/ route=node1 loadfactor=1
ProxySet lbmethod=byrequests
</Proxy>
ProxyPreserveHost On
ProxyPassMatch ^/(.*\.cf[cm]/?.*)$ balancer://mycluster/$1 nofailover=On
The only real difference is the conversion of the ProxyPass directive to ProxyPassMatch, as was said earlier this will pass only cfm and cfc calls on to Tomcat and let Apache deal with all of the static files. This means you need to set up a 404 handler in Apache for missing files, and subsequently a missing template handler for missing cfc or cfm files.
Using ProxyPassMatch should help you squeeze more performance out of your machine since Tomcat will now only be involved in processing Coldfusion instead of having to return static content as well. You should still tune your jvm settings as suggested by Railo and do other performance tuning exercises based on your specific needs.
zurück