Wednesday, February 25, 2009

Tomcat Reverse Proxy

There are two Apache Tomcat connectors can be used Tomcat reverse proxy: mod_jk and mod_proxy_ajp.

mod_proxy_ajp is new and easy to configure while mod_jk is just the opposite. I would not explain the details how to use them since this type of info can be easily found online. I just want to share what I found after weeks of frustration:
  • Use mod_proxy_ajp when your network connection between the proxy and Tomcat is very stable, and the traffic load is low.
  • Otherwise use mod_jk.
  • By default, Tomcat does NOT recycle abandoned ajp connections. You need to enable that, otherwise, broken network connections between proxy and Tomcat will max out ajp thread pool on Tomcat side.
Below settings in works.properties file is helpful in mod_jk configuration:

worker.gui2.socket_timeout=10
worker.gui2.socket_keepalive=True
worker.gui2.reply_timeout=500
worker.gui2.prepost_timeout=10000
worker.gui2.connect_timeout=10000
worker.gui2.retries=5
worker.gui2.connection_pool_timeout=600
If everything fails to maintain stable connection, disable connection reuse in Apache .conf file:

JkOptions +DisableReuse
To enable Tomcat recycle abondaned ajp threads, add:
connectionTimeout="600000"

to server.xml file.

No comments: