JBoss application server production settings and performance tuning

Introduction

JBoss AS is a Java application server widely used for Web application development, testing and production deployment. The community edition of JBoss is free and open source and is ideal for development and testing. The commercial edition known as JBoss enterprise application platform is the ideal choice for production hosting. However in many intranet projects community edition is also used for production hosting. In this article I will cover JBoss production settings and performance tuning techniques.

JBoss can be used for large scale deployments and supports load balancing, clustering, EJBs and a large set of J2EE specifications. The current production version of JBoss is 5.1 and JBoss application server 6.0 may be released in November 2010. Please note that the following guide uses community edition of JBoss 5.1. I also assume that you are hosting JBoss in a Windows 2008 or Windows 2003 server. However the steps given are similar for Unix/Linux systems such as Fedora, Ubuntu and RHEL.

Prerequisites for Running JBoss Server

Before we take up any of the following steps, it is necessary to fix the JBoss version to be used, the JVM version, the platform for hosting JBoss and whether clustering is required. These decisions are dependent on application requirements and current enterprise architecture of the customer.  For the examples below I use Java 1.6, JBoss AS 5.1 and Windows 2003 server.image

  • Download & install Java – JBoss application server requires either Java 1.5 or Java 1.6 installed on the host machine. You can download Java from here. I recommend installing Java 1.6.
  • Download & install JBoss application server – JBoss 5.1 can be downloaded in binary form from here. This contains a platform independent release of JBoss server. To install, just extract the zip file to a folder of your choice. The image on the right shows the folder structure of JBoss server installation.

JBoss Application Server Fundamentals

JBoss Server 5 uses a new architecture known as the Microcontainer which is a lightweight container for managing POJOs and their lifecycle. It also brings complete support for Java EE5.

JBoss 5 comes with 5 different server configurations by default. These are all, default, minimal, standard and web. These configurations are present as different folders under the server folder (see image). These configurations have different capabilities. When you go to production, you will have to pick one of these and then customize it for production settings. The easiest would be to pick "default" configuration and then remove any services not required by your application. Another way would be to pick "minimal" configuration and then add required services for your application. Removing unwanted services is easier and hence I will use the "default" configuration below.

If you are using any server configuration other than "default" you will have to specify it in the command line of the server startup script. For example use the following command to run "minimal" configuration. 

W:\tools\jboss-5.1.0.GA>run -c minimal

JBoss works "out of the box" and applications can be deployed just by dropping application WAR/EAR files to the application server’s deploy  folder. If you are using "default" configuration, this folder is server/default/deploy.

Configuring JBoss in a Production Server – Step by Step Guide

Step 1 – Configuring Startup Scripts

The first thing I did was to create a set of customized startup/shutdown scripts for JBoss Server. These were copied to the desktop so that it is easy to start or stop the JBoss instance. Also note that I bind the server to all available network interfaces by using the bind option (-b). The configuration option (-c) can be used to select a server configuration and it is optional for "default" configuration.

startjboss.cmd

w:
cd w:\tools\jboss-5.1.0.GA\bin
run.bat -b 0.0.0.0 -c default

stopjboss.cmd

w:
cd w:\tools\jboss-5.1.0.GA\bin
shutdown.bat -S

As you can see both these scripts are actually calling default scripts provided in the JBoss’ bin folder.

In the startup script the -b argument (binding ip) indicates the IP to which the server session is to be attached. 0.0.0.0 indicates that the server must be accessible from all ips including localhost (it binds the JBoss server to all ip addresses of server machine). If you don’t specify this, JBoss will be accessible only from 127.0.0.1.  

Step 2 – Configuring JVM Memory Settings

The run.conf.bat file in the bin folder contains JVM parameters including memory configuration. In the production server, ensure that these values are correctly set. For example, the following sets the minimum and maximum heap size as 1GB. It is better to keep them identical for performance reasons. The actual heap size setting will depend on your application requirements and also on the RAM size of the server machine.

set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx1024m"

Also ensure that adequate permgen space is set. Permgen space is the fixed memory required such as the code footprint. For large applications the default value of 256m may not be sufficient. Following sets the permgen space to 512MB.

set "JAVA_OPTS=%JAVA_OPTS% -XX:PermSize=512m -XX:MaxPermSize=512m"

If you want to fine tune JVM settings, you can try changing parameters such as NewSize, MaxNewSize and Survivor Ratio. See this page for more details.

Step 3 – Changing Default HTTP Port to 80

The HTTP port for default JBoss installation is 8080. In production server, you will require this to be on port 80 (default HTTP port).  If you are using HTTPS, you will need to change SSL port from 8443 to 443. In JBoss 5, changing default ports are easy. You just need to modify only one file.

(a) default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml

Open this file and then modify Web server properties located towards the end of the file. You can also search for 8080 and 8443. 

Step 4 – Configuring Datasource Settings

The datasource settings are stored in xml files under deploy folder of the server. For example, oracle-ds.xml is the configuration file I used in my application. This maps a connection setting to a JNDI name. The important parameters to configure are,

min-pool-size – This is the initial number of connections kept open to database.
max-pool-size – This is the maximum number of concurrent connections possible to the database. This value should be based on your application needs and also on the database configuration.

Step 5 – Configuring HTTP Connector Settings

The underlying HTTP connector of JBoss needs to be fine tuned for production settings. The following settings are applied to the Connector tag in the default/deploy/jbossweb.sar/server.xml file. The important parameters are,

maxThreads – This indicates the maximum number of threads to be allocated for handling client HTTP requests. This figure corresponds to the concurrent users that are going to access the application. Depending on the machine configuration, there is a physical limit beyond which you will have to do clustering.

acceptCount – This is the number of request threads that are put in request queue when all available threads are used. When this exceeds, client machines get a request timeout response.

compression – If you set this attribute to "force", the content will be compressed by JBoss and will be send to browser. Browser will extract it and display the page on screen. Enabling compression can substantially reduce bandwidth requirements of your application.

Step 6 – Configuring JSP Compilation Settings for Production

JBoss application server regularly checks whether a JSP requires compilation to a servlet before executing a JSP. In a production server, JSP files won’t change and hence you can configure the settings for increased performance.

Open the web.xml in default/deployers/jboss-web.deployer folder. Look for the jsp servlet (org.apache.jasper.servlet.JspServlet) in the file and modify the following XML fragment as given below,

<init-param>
            <param-name>development</param-name>
            <param-value>false</param-value>
</init-param>
<init-param>
            <param-name>checkInterval</param-name>
            <param-value>300</param-value>
</init-param>

Step 7 – Removing unwanted applications and services

JBoss comes with a lot of services and your enterprise applications may not need all of them.  Removing these unwanted services can boost application server performance. Following are some of the JBoss services you can remove if your application is not using them in production. Delete the files/folders given in brackets to remove these services completely.

(a) Home page server- (deploy/ROOT.war)
(b) JMX Console server – (deploy/jmx-console.war)
(c) Web Console server – (deploy/management)
(d) Unique ID key generator -  (deploy/uuid-key-generator.sar, lib/autonumber-plugin.jar)
(e) HTTP Invoker service – (deploy/http-invoker.sar)
(f) Quartz scheduler service – (deploy/quartz-ra.rar)
(g) Mail service – (deploy/mail-service.xml, lib/mail*.jar)
(h) Monitoring service – (deploy/monitoring-service.xml,lib/jboss-monitoring.jar)
(i) Scheduler service – (deploy/scheduler-service.xml, deploy/schedule-manager-service.xml,lib/scheduler-plugin*.jar)
(j) Messaging (JMS) service – (deploy/messaging, deploy/jms-ds.xml, deploy/jms-ra.rar, lib/jboss-messaging*.jar)

Step 8 – Protecting Administration Console Applications

Some of the default Web applications in JBoss are very useful in monitoring server status. For example the Web Console can give valuable information such as server memory status and active HTTP active connections. Please see the Web Console screenshot below (http://localhost/web-console/),

So you may decide to leave them enabled on the JBoss production server. But the problem is that these can be accessed by anyone through Internet and is unprotected. When you run JBoss with production settings you obviously want to protect these applications.

You can protect these applications using JAAS or by limiting access to these applications only from the local machine (server machine). Of course the easiest way to secure them is to remove them as I have shown in the previous section. In order to enable access only from local machine,

Add the following in server.xml (default/deploy/jbossweb.sar) just before "Engine" closing tag.

<Host name="loopback" autoDeploy="false" deployOnStartup="false" deployXML="false">
</Host>

Then add the following in jboss-web.xml in WEB-INF of the following admin applications.

<virtual-host>loopback</virtual-host>

For JMX Console  use deploy/jmx-console.war and for Web Console use deploy/management folder. Now these monitoring apps can be accessed only  from http://loopback address.

Step 9 – Configuring Log4J Logging for Production

The default logging configuration in JBoss is not suitable for production deployment. In production, you only want the errors to be logged. Open jboss-log4j.xml file in default/conf folder.

First change the root category located at the end of the file jboss-log4j.xml to contain only FILE appender. This ensures that there is logging to the screen (CONSOLE) and all errors are only logged to a file.

   <root>
      <appender-ref ref="FILE"/>
   </root>

Then add the following limiting categories.

   <category name="org">
      <priority value="ERROR"/>
   </category>
   <category name="com">
      <priority value="ERROR"/>
   </category>
   <category name="net">
      <priority value="ERROR"/>
   </category>

Remove the following entries. Please note that the following list is not exhaustive. You can remove all categories and then add the three categories given above. This ensures that only errors are logged. Also the changes  to the logging configuration is hot deployed within a minute and hence you don’t need to restart the server.

   <category name="org.apache">
      <priority value="INFO"/>
   </category>
   <category name="org.quartz">
      <priority value="INFO"/>
   </category>
   <category name="org.jboss.management">
      <priority value="INFO"/>
   </category>
   <category name="org.jboss.serial">
      <priority value="INFO"/>
   </category>

Another simpler way to control logging is to change the priority attribute of the root logger. Set it to ERROR as shown below.

   <root> 
      <priority value="ERROR"/>
      <appender-ref ref="FILE"/>
   </root>

October 28, 2010 | Posted in Programming 3 Comments » | By Jayson

3 Comments to “JBoss application server production settings and performance tuning”

  1. can one process ocupy the whole cpu while other processes are idle? Says:

    […] options Here are some links to look at: http://java.dzone.com/articles/java-performance-tuning http://www.jaysonjc.com/programming/…ning-tips.html http://java.sun.com/developer/techni…/jconsole.html <= Pay particular attention to #/threads, […]

  2. Raja Says:

    Excellent…. Very useful for basic level setup and having a nice information.

  3. Aumente a performance do JBoss - Dimensão Tech Says:

    […] ser preciso fazer um ajuste fino das configurações para ganhar performance (Tunning). O artigo JBoss application server production settings and performance tuning vai lhe ajudar neste assunto. Últimos 5 artigos de Eduardo CostaWindows God ModeDica: Trave seu […]

Leave a Comment