When tomcat is installed in a directory with spaces , and used for struts application you may get a
NullPOinterException
com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209)
This will be fixed in the future versions of the xwork jar , else you need to download the latest code from their branch and build the jar.
There is alternative to this , this error can be avoided by setting
struts.devMode=false
Saturday, April 11, 2009
Bug when Tomcat 6(installed in directory with spaces) and Xwork
Tuesday, April 7, 2009
Configuring Logging for Tomcat on Eclipse
When tomcat is added as a server under Eclipse thw logs are displayed on the console and it never comes under the logs of tomcat neither in eclipse workspace.
It can be configured to do so by
Double Clicking the newly added server in the Servers menu
1. In General Information
Click Open Launch Configurations - >
-> Add the required arguments in the argument tab ,
-> and in the Common tab you can mention weather the output the to be on the console or piped int o any other log file ion the disk.
Refer this to enable JULI logging on the Server Instance
http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_enable_the_JULI_logging_in_a_Tomcat_5.5_Server_instance.3F
2. In the Server Location - you can choose User Tomcat Installation which will take control on the tomcat installation directory and all application under it will also be deployed
Enabling Access Logs on Tomcat 6
Tomcat 6 has a new feature which logs access logs. This can be easily enabled by uncommenting the required code in the conf/server.xml.
<valve classname="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolvehosts="false">
</valve>
This can be embedded for the Host or per context basis
Sunday, March 15, 2009
Tomcat Connectors
Typically Communication protocol between apache and tomcat is AJP
Apache used mod_jk to speak AJP(Apache Jserv Protocol) to tomcat .
AJP is a binary packet based protocol - hence difficult to debug and limitation on packet size
- AJP on tomcat side
Java Connector(BIO) - Blocking IO , one thread per connection
APR Connector - Allows more connections , allows polling
Java NIO Connector
- Tomcats Http Connectors - can replace AJP specific features ,more options , more control ,Finely tuned,easy to debug since its text based
Nio , APR Connectors, BIO - fastest when not using persistent connections
- mod_proxy_http - for HTTP - native protocol level support for authentication and SSL
- HTTP Connector -
o.a.coyote.http11.Http11Protocol (BIO)
o.a.coyote.http11.Http11AprProtocol (APR)
o.a.coyote.http11.Http11NioProtocol (NIO)
HTTP/1.1 aliased to Http11 and Http11Apr depending on PATH or LD_LIBRARY_PATH settings
- AJP Connector -
org.apache.jk.server.JkCoyoteHandler
org.apache.coyote.ajp.AjpAprProtocol
AJP/1.3 aliased to the two above
Depending on PATH or LD_LIBRARY_PATH settings
- Use BIO if
Stability is the highest priority APR and NIO are more recent
Most content is dynamic
Keep alive is not a determining factor
protocol=“org.apache.coyote.http11.Http11Protocol”
protocol=“HTTP/1.1”
- Use APR if
SSL is terminated at Tomcat
Platforms are Linux or Windows
Keep alive is important
Lots of static content
Using Comet feature
protocol=“org.apache.coyote.http11.Http11AprProtocol”
- Use NIO if
Compiling APR is not an option
SSL is terminated at Tomcat
Keep alive is important
Lots of static content
Using Comet features
protocol=“org.apache.coyote.http11.Http11NioProtocol”
- requirement connectors in preference order
Stability --> Bio, APR/NIO
SSL --> APR,NIO,BIO
Low Concurrency --> BIO,APR,NIO
High Concurreny with keepAlive --> BIO,APR,NIO
Hig Concurrency with no keep alive -->APR,NIO,BIO
- The native APR connector is unstable on Solaris
Performance Optimization for Tomcat
1. Clear the webapp directory in tomcat ( unnecessary loading of example and non essential applications)
2. Remove Duplicate Logging in Tomcat which comes by default
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler can be removed as logging is a costly operation
3. Using Asynchronous logging .
Tomcat by default using synchronous logging ,we can use log4j to change the default behavior
Synchronous logging (logging.properties) Can become a bottleneck
We don’t want disk IO to become the limiting factor
4. The following should be considered for choosing the connectors
BIO stablity, static content offloaded into other server only dynamic content is present , keep alive non essential
APR ssl terminating at tomcat (because of openssl library it uses ),keep alive imp , also servers static content
NIO ssl terminating at tomcat, keepalive imp, static content
(keep alive becomes because SSL connection is costly )
check out separate blog on Tomcat Connectors ...
5. Best practice
Maintain a separate setenv.bat file which will be automatically called by tomcat 6 , which has custom settings(also Vm params).
This helps in easy migration
Use catalina.properties for server.xml substitution variables
6. Avoid using the log() methods in the Servlet API
7. Apache log4j
– log4j.properties in /WEB-INF/classes
– log4j-x.y.z.jar in /WEB-INF/lib
no seperate initializations required
8 . Have overflow protection for logs using cronolog
Overflow protection (logging.properties) Size based rotation using JVM logger
www.cronolog.org
9. In highly concurrent environments turn off KeepAlive
If its on , the socket stays connected and waits for the given time interval
10. Tuning Parameters
maxThreadsTypical
Maximum nr of concurrentrequests
For BIO, max nr of open/active connections
maxKeepAliveRequests
Typical values 1, 100-200
Represents the number of requests Tomcat will handle on a TCP connection
Set to 1 disables keep alive
connectionTimeout/keepAliveTimeout controls the timeout in between requests
maxKeepAliveRequests
Set to 1 if Very high concurrency
acceptCount
Represents nr of additional connections the OS should accept on your behalf
Useful when Tomcat can’t accept connections fast enough
connectionTimeout
Represents the SO_TIMEOUT value
Essentially, max time between TCP packets during a blocking read or write
Critical to a stable system
Also used for keep alive timeout
11. Enable caching for Static conetnt , will help in faster access from disk
Configured in
•40MB cache (default 10MB)
•cache revalidation every 60 seconds (default 5 seconds)
•caching enabled (default true)
12. GC Settings –JDK 1.5 and 1.6
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:CMSIncrementalDutyCycleMin=0
-XX:CMSIncrementalDutyCycle=10
-XX:+UseParNewGC
-XX:+CMSPermGenSweepingEnabled
-XX:MaxGCPauseMillis=250
-XX:MaxGCMinorPauseMillis=100
13.
Thursday, March 5, 2009
Tomcat Version In Spring Dm OSGi
Spring DM Server comes with Tomcat 6.0.18, which I believe is the latest one.
You can see the latest version by looking at
DM_SERVER_HOME/repository/bundles/ext/ and
look at Catalina bundles (i.e., com.springsource.org.apache.catalina-6.0.18.jar)
Wednesday, March 4, 2009
Removing tomcat from Spring Dm to reduce memory
By commenting out the servlet subsystem, there should be no Tomcat running in dm Server ß
In profile.config comment as indicated below to disable the tomcat instance.
/* * SpringSource dm Server profile manager default configuration file. */
"profile": { "version" : 1.0, "name" : "web", "subsystems" : [/* "com.springsource.server.servlet", "com.springsource.server.web" */], "optionalSubsystems" : [/* "com.springsource.server.management" */] }}
Mem usage
WITH TOMCAT - 68MB W
WITHOUT TOMCAT - 51 MB ( so 17 MB less)
Ref :http://forum.springframework.org/showthread.php?p=216805
.jpg)