Professional Documents
Culture Documents
JBoss Tuning
Run, Forrest, Run!
EIS
EIS
EIS
Tune, monitor
and secure
Configure Configure
Administrator
JBoss
Application
Choice of JVM
There are multiple choice of JVM’s, among them Sun HotSpot JVM
and BEA Jrockit JVM are most popular
Note1 : Use a 64 bit machine and 64 bit VM so that you can use large
heap sizes
Note2 : Avoid extra large heaps but avoid extra small heaps.
Every JVM includes options that can affect performance – the most
prevalent of which are:
- heap size - garbage collection - Threading
The head size is the amount of memory that the JVM has to work with.
Jboss server code and Jboss application code create instances of Java
classes that are held in this memory. By default, Jboss executes with an
intial heap size of 64MB(for WebLogic 32MB)
Tomcat Tuning
<Connector port="8080"
address="${jboss.bind.address}" maxThreads="150"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443"
acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true"/>
1)You should have minSpareThreads equal just a little more than your
normal load
2)You should have maxSpareThreads equal just a little more than your
peak load
3)min spare threads means "on start up, always keep at least this many
threads waiting idle"
5)Remove any unnecessary valves and logging. If you're not using JBoss's
security, remove the security valve (see below).
<mbean code="org.jboss.web.tomcat.tc5.Tomcat5"
name="jboss.web:service=WebServer">
attribute name=”DeleteWorkDirs”> true</attribute>
...
</mbean>
Ref :deploy/jbossweb-tomcat5x.sar/META-INF/jboss-service.xml
Classloading Behavior
<mbean code="org.jboss.web.tomcat.tc5.Tomcat5"
name="jboss.web:service=WebServer">
attribute name=”Java2ClassLoadingCompliance”>
true</attribute>
...
</mbean>
Ref :deploy/jbossweb-tomcat5x.sar/META-INF/jboss-service.xml
deploy/jbossweb-
tomcat5x.sar/conf/web.xml
<!-- The JSP page compiler and execution servlet, which is the mechanism
used by Tomcat to support
<!-- JSP pages. Traditionally, this servlet is mapped to URL pattern "*.jsp".
This servlet supports the
<!-- following initialization parameters (default values are in square
brackets):
<!--
<!-- checkInterval If development is false and reloading is true,
background compiles are enabled.
<!-- checkInterval is the time in seconds between checks to see if a JSP
page needs to be recompiled. [300]
<!--
<!-- development Is Jasper used in development mode (will check for JSP
modification on every access)?
<!--
<!-- reloading Should Jasper check for modified JSPs? [true] 15
© JBoss, Inc. 2003-2005
JSP Optimization
Professional Open Source™
deploy/jbossweb-
tomcat5x.sar/conf/web.xml
<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>
<load-on-startup>3</load-on-startup>
</servlet>
Incoming connections:
– From HTTP server (Apache/IIS via mod_jk)
• AJP protocol
– Direct client connections
• HTTP/HTTPS
HTTP
HTTP
mod_
AJP
jk
deploy/jbossweb-tomcat5x.sar/server.xml
<Service name="jboss.web“
className="org.jboss.web.tomcat.tc5.StandardService">
Better scalability
– Keep a minimal pool of threads: minProcessors (4.1) and
minSpareThreads (5.0)
– Allow more concurrent connections: maxProcessors (4.1) and maxThreads
(5.0)
– Many other factors, obviously: the worst is to allow too many HTTP
connections that couldn't complete in a satisfactory time
– ConnectionTimeout, disableUploadTimeout and maxKeepAliveRequests
allow configuring HTTP/1.1 keepalive
– Attribute ”acceptCount”
• Maximum queue size when all threads are busy processing
Used when:
– Reading cookies
– Accessing the request parameters
– Accessing the request headers (cache related headers, etc)
Configured using system properties
– tomcat.util.buf.StringCache.byte.enabled and
tomcat.util.buf.StringCache.char.enabled : Set to true to enable byte[] or char[] to
String conversion caching.
– tomcat.util.buf.StringCache.trainThreshold: The cache will be built after a training
period during which statistics about converted Strings will be kept. The value of this
property is the amount of String conversions before building the cache.
– tomcat.util.buf.StringCache.cacheSize: Maximum number of String objects which
will be cached, according to their usage statistics.
Runtime monitoring through JMX
– Mbean name: Catalina:type=StringCache
– Can be enabled or disabled at runtime by changing the enabled attributes
– reset operation to discard the current cache and start collecting statistics to build a
new one; this can be used after deployment of new applications on the server
•edit server/test/con/standardjboss.xml
•change all of the proxy bindings to the pooled invoker by changing
every XML fragment reading:
<invoker-
mbean>jboss:service=invoker,type=jrmp</invoker-
mbean>
to
<invoker-
mbean>jboss:service=invoker,type=pooled</invoker-
mbean>
© JBoss, Inc. 2003-2005 25
Professional Open Source™
Log4J
Jboss provides an Mbean that can be used for configuring logging options.
This Mbean is normally defined in the root configuration file
\conf\jboss-service.xml.
Mbean Definition
<mbean code=“org.jboss.logging.Log4jService”
name=“jboss.system:type=Log4jService.service=Logging”>
<attribute
name=“ConfigurationURL”>resource:log4j.xml</attribute>
<attribute name=“Log4jQuietMode”>true</attribute>
</mbean>
This will load the logging configuration from the file \conf\log4j.xml
<appender name="CONSOLE"
class="org.apache.log4j.ConsoleAppender">
<errorHandler
class="org.jboss.logging.util.OnlyOnceErrorHandle
r"/> <param name="Target"
value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
1.Edit server/slim/conf/log4j.xml
2. Remove comment these XML fragments
.
<category name="org.apache">
<priority value="INFO"/>
</category> <!-- Limit org.jgroups category to INFO
-->
<category name="org.jgroups">
<priority value="INFO"/>
</category>
The priority value can be one of:
•ERROR - error messages
•WARN - borderline error messages
•INFO - general status messages
•DEBUG - verbose debug level messages
•TRACE - very verbose
© JBoss, Inc. 2003-2005 31
Log4J
Professional Open Source™
And finally, probably the most important thing in log4j, make sure
you limit the logging level on your own class hierarchy. This
assumes that you are using log4j as it was intended and not writing
everything to System.out. This will significantly reduce the overhead
of log4j and allow you to fully enjoy the benefits of calls like "if(
log.isDebugEnabled() )...". If you don't do this then all the logging in
your code will get formatted and passed to the appender, and the
threshold on the appender will weed out the log messages. This can
generate a significant amount of garbage. Assuming your java
package starts with "a.b", add something like this to log4j.xml:
Deployment Scanner
If you find that you need more than the default (10) instances consider
setting the minimum pool size:
and find:
<container-pool-conf>
<MaximumSize>100</MaximumSize>
</container-pool-conf>
</container-configuration>
change it to read:
<container-pool-conf>
<MinimumSize>100</MinimumSize>
<MaximumSize>100</MaximumSize>
<strictMaximumSize>100</strictMaximumSize
>
</container-pool-conf>
</container-configuration>
For example, there can be issues with the number of database accesses that
an application is making, which might encourage an application developer
to cache in memory values that don’t change frequently instead of retrieving
each time. Or there could be an issue with how long a particular query is
taking to return, which might be improved by adding indexes or using
temporary tables on the database.
There are several other factors concerning the general performance of the
database itself as well as Jboss communication with the database
© JBoss, Inc. 2003-2005 39
Database and SQL Tuning
Professional Open Source™
1. Connection Pools
2. Caching Prepared Statements
3. JDBC Driver Type
4. Database Schema Design
5. Using Correct Indexes
6. Using Strored Procedures
Connector Tuning
Sample datasource:
<datasources>
<local-tx-datasource>
<jndi-name>GenericDS</jndi-name>
<connection-url>[jdbc: url for use with Driver class]</connection-
url>
<driver-class>[fully qualified class name of java.sql.Driver
implementation]</driver-class>
<user-name>x</user-name>
<password>y</password>
<!-- you can include connection properties that will get passed in the
DriverManager.getConnection(props) call. Look at your Driver
docs to see what these might be -->
<config-property name="SomeProperty"
type="java.lang.String">x</config-property>
<connection-property name="char.encoding">UTF-8</connection-
property>
<transaction-isolation>TRANSACTION_SERIALIZABLE</transaction-
isolation>
<!--pooling parameters-->
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
<prepared-statement-cache-size>100</prepared-statement-cache-
size>
© JBoss, Inc. 2003-2005 44
Connector Tuning
Professional Open Source™
Configuration Options
– Set the appropriate database connection pool size
• Depending on how many concurrent requests you’re handling
– E.g. how many concurrent requests are coming through web tier?
– How many of those requests need database access?
• Try the prepared statement cache for performance
• Try switching track-statements to false for performance
Slimming
•remove server/slim/deploy/mail-service.xml
•remove server/slim/lib/mail* (mail-plugin.jar,
mail.jar - JavaMail? stuff)
•remove server/slim/lib/activation.jar (Java
Activation Framework is used by JavaMail?)
•remove server/slim/deloy/cache-invalidation-
service.xml
•remove server/slim/deploy/client-deployer-
service.xml
When not using the HTTPInvoker (which lets you tunnel RMI over
HTTP)
•remove server/slim/deploy/jboss-xa-jdbc.rar
•remove server/slim/deploy/jmx-console.war
If you are not using the JBoss Scheduler Manager (allows you
to schedule invocations against MBeans)
•remove server/slim/deploy/schedule-manager-service.xml
•remove server/slim/lib/scheduler-plugin* (scheduler-
plugin.jar, scheduler-plugin-example.jar)
•open server/slim/deploy/jbossweb-tomcat50.sar/server.xml -
-- remove/comment the following XML fragment:
MBean
<attribute
name="EARDeployer">jboss.j2ee:service=EARDeploy
er</attribute>
and
<!-- EAR deployer, remove if you are not using Web
layers --> <mbean
code="org.jboss.deployment.EARDeployer"
name="jboss.j2ee:service=EARDeployer">
</mbean>
© JBoss, Inc. 2003-2005 59
Slimming
Professional Open Source™
•open server/slim/conf/jboss-service.xml
•remove
Tomcat Status: