Peter Roßbach, core developer at the Tomcat project, held a talk at RheinJUG in Düsseldorf on Thursday. It was very delightful mixture on Tomcat architecture, best practices, Open Source community as well as current and future developments, rather than a dry technical talk.
Tuning Tomcat Performance
Regarding performance, he mentioned that the main negative factor is to use development mode for production environments. Well have a look at a few parameters and which do affect Tomcat performance.
As of tomcat 6 there is the improved protocol handler available:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" />
additionally Java NIO powers a new improved file download option. Servlets just have to set sendfile request parameters and not output any more data. That file will then be pushed by tomcat to the user:
org.apache.tomcat.sendfile.filename: Canonical filename of the file which will be sent as a String org.apache.tomcat.sendfile.start: Start offset as a Long org.apache.tomcat.sendfile.end: End offset as a Long
production servers should not deploy automatically:
<Host name="localhost" autoDeploy="false" deployOnStartup="false" deployXML="false">The Jasper JSP compiler should be tuned as well:
<servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>development</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>genStringAsCharArray</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>trimSpaces</param-name> <param-value>true</param-value> </init-param> </servlet>
Using mod_jk for loadbalancing
As a second main topic of his talk, he presented the module “mod_jk”, which in connection with a Apache Httpd and the Tomcat AJP protocol enables distributing java applications on multiple Tomcat servers.
He explained the different loadbalancing setups and that it might make even sense to user a Tomcat server per application, as this allows better memory management and improves overall high-availibility.
Tomcat Configuration:
<Connector port="8009" protocol="AJP/1.3"/> <Engine name="Catalina" defaultHost="localhost" jvmRoute="node01">
mod_jk Configuration inside Httpd:
<IfModule !mod_jk.c> LoadModule jk_module "modules/mod_jk.so" </IfModule> JkShmFile "logs/mod_jk.shm" JKWorkerProperty worker.list=loadbalancer JKWorkerProperty worker.node01.port=8009 JKWorkerProperty worker.node01.host=localhost JKWorkerProperty worker.node01.type=ajp13 JKWorkerProperty worker.loadbalancer.type=lb JKWorkerProperty worker.loadbalancer.connection_pool_minsize=0 JKWorkerProperty worker.loadbalancer.connect_timeout=30000 JKWorkerProperty worker.loadbalancer.prepost_timeout=10000 JKWorkerProperty worker.loadbalancer.balance_workers=node01 JKWorkerProperty worker.loadbalancer.method=Request JKWorkerProperty worker.loadbalancer.retries=2 JKWorkerProperty worker.loadbalancer.recovery_options=7 JKMount /myapps* loadbalancer
Further documentation on mod_jk worker can be found here:
http://tomcat.apache.org/connectors-doc/reference/workers.html
In total a very interesting talk, with lots of stuff to learn from, let it be the Tomcat project or the Tomcat architecture, or how Open Source “lives” and what one as developer or architect should consider when developing a Java web application.








category:

