Load Balancing in Adempiere

With increasing demand for powerful web application and near zero tolerance for downtime, the need for fail over and load balancing has become kind of implicit. This article gives you an overview of how to implement load balancing for Adempiere or any application built on the Adempiere framework. It goes on talks about how to configure different nodes ( application instances) for a single load balancer which will distribute the load ( traffic ) among the nodes and how to configure the load balancer.

Problem Statement

When an application is deployed and used by large number of users, the number of request for server at single point of time reduces the performance (increases the overall response time) of the application. Also, due to any reason, if the server goes down then application becomes unavailable for the time being. To overcome this the best way is to distribute the load i.e the requests between the instances of the application, like multiple instances (nodes) of the same application running on different hosts. In this way the load/traffic will be distributed between the nodes so that all the request can be served with efficiently and in case something goes really wrong with instance then the other instance ensure continuity of the business.

Following image shows the overall architecture for load balancing:
Load Balancer


As prerequisites for load balancing you need to have below software’s installed.

Apr( Apache Portable Runtime) 1.4.X

Apr is a supporting library for the Apache web server. It provides a set of APIs that map to the underlying operating system (OS). Where the OS doesn’t support a particular function, APR will
provide an emulation. Thus programmers can use the APR to make a program truly portable across platforms.

Apr-Util ( Apache Portable Runtime util) 1.3.x

Apr-Util is a utility library used with the Apache Portable Runtime (APR). It aims to provide a free library of C data structures and routines. This library contains additional utility interfaces for APR; including support for XML, LDAP, database interfaces, URI parsing, and more.

Apache server 2.X

Apache web server of 2.x verison

ModJk ( 2.x)

Mod_jk is the connector used to connect the Tomcat servlet container with web servers such as Apache, Netscape, etc. using the AJP protocol. In a nutshell, a web server waiting for the client HTTP requests. When these requests arrive the server does whatever is needed to serve the requests by providing the necessary content. In case this is used with servlet container, the web server needs to perform the following as well:

  1. Load the servlet container adapter library and initialize it (prior to serving requests).
  2. When a request arrives, it needs to check and see if a certain request belongs to a servlet, if so it needs to let the adapter take the request and handle it.

The adapter needs to know what requests it is going to serve, usually based on some pattern in the request URL, and to where to direct these requests. Things are even more complex when the user wants to set a configuration that uses virtual hosts, or when they want multiple developers to work on the same web server but on different servlet container JVMs.

How to install Apr for linux?

    1. Download the binaries of Apr from Apache site http://apr.apache.org/download.cgi
    2. Extract the downloaded tar file through command prompt
    3. Go to the extracted directory and
    4. Run following commands:
  1. /configure –prefix=/desired/path/of/apr ( path where you want to install the apr binaries)
  2. make
  3. make test
  4. make install

How to Install Apr-Util for linux?

    1. Download the binaries of Apr-Util from Apache site http://apr.apache.org/download.cgi
    2. Extract the downloaded tar file through command prompt
    3. Go to the extracted directory and
    4. Run following commands
  1. ./configure –prefix=(path where you want to install apr-util) –with-apr=(path of the apr installed directory)
  2. make
  3. make install

How to install Apache Server for linux?

  1. Download the binaries of apache-server-2.x server http://httpd.apache.org/download.cgi#apache22
  2. Extract the downloaded tar file through command prompt
  3. Go to the extracted directory
  4. Run following commands
    1. $ ./configure –prefix=PREFIX (path where you want to install apache)
    2. $ make
    3. $ make install
  • Change the listen port from 80 to other if required. Also, modify PREFIX/conf/httpd.conf file with the changed value.

How to Install ModJk for Linux?

  1. Download mod_jk( tomcat_connectors) from the url http://apache.tradebit.com/pub//tomcat/tomcat-connectors/jk/
  2. Extract the downloaded tar file
  3. Go the extracted directory and run following commands
    1. $ cd native
    2. $ ./configure -prefix=PREFIX (path where you want to install apache) –with-apxs=APACHE_HOME/bin/apxs

If you get error about cc1plus the locate the cc1 file in your system and set it to the cc1plus path as shown below
ln -s /usr/libexec/gcc/i586-redhat-linux/4.4.1/cc1 cc1plus

System Requirements

  1. Adempiere 3.6
  2. Sun/Oracle JDK 1.5/1.6 depending upon the ADempiere version
  3. PostgreSQL 8.x or above
  4. JBoss 4.2.x or above


The Apache Software like Apache Server, Apr and Mod_jk need to be installed on load balancer host. JBoss Application Server Supports Load Balancing with the help of Apache Software listed in prerequisites section. The first thing you need to do is to configure Mod_Jk with the Apache server. Prepare a file with the name mod-jk.conf, and file should contain the below details and place this file in APACHE_HOME/conf

# Load mod_jk module
# Specify the path of the of the mod_jk lib i.e mod_jk.so relative from the
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties , which contains the workers details
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
Load Balancer
Node 1 (host where the
application running in
jboss app server)
Node n (host where the
application running in
jboss app server)
# Mount your applications
JkMount /jkmanager/* jkstatus
# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm
# Add jkstatus for managing runtime data

JkMount jkstatus
Order deny,allow
Deny from all
Allow from


The Apache Server should know that the mod-jk is configured and it should also know where to find the configuration file of the mod-Jk. To tell this to Apache Server add the below to the httpd.conf file in the conf in the APACHE_HOME.
Include conf/mod-jk.conf

As mentioned in the above mod-jk.conf file you need to define workers.properties file which will have the details of the nodes in the load balancing, and the uriworkermap.properties file. Mod_jk will route the requests received between the nodes configured in workers.properties file based on the round robin algorithm and the weighted round robin algorithm. To do this load balancer need to know what are the nodes to which it should route the request. Prepare a file with name workers.properties and list the details of the nodes you want to add to the load balancer as shown below:
# Define Node1
# modify the host as your host IP or DNS name.
# ajp port number of the node
# host as your host IP or DNS name
#type should be ajp and ajp1.3 is the latest so use ajp13
# lbfactor is the load balancing factor for the node. The weight of the lbfactor
increases more request #will be routed to the node. Like higher the number higher
the priority of the node.
# Define Noden
# modify the host as your host IP or DNS name.
#Load-balancing behaviour
#node's names with the comma seperated to route the requests
#if the value of the worker.loadbalancer.sticky_session=0/false the session
affinity will not #implemented i.e the every request will be load balanced.
#if value is 1/true session affinity will be implemented i.e once the session
initiated for a request the
#feature request's with the same session will be routed to same server.
# Status worker for managing load balancer

Now we’ve told mod_jk about our setup. If you are using sticky sessions, you’ll need to tell Tomcat to append its node-id to the session id. This needs to be the same as worker.name.jvm_route, which by default is the worker’s name. This is important if you want to send request from same client on same server.

Configuration At Nodes

The application server node’s jboss app server needs to know that the it is one of the node under the load balancer and its name to append its name to the jsession so that the mod_jk will route the future with the same jsession to the same node.

Modify jboss/deploy/jboss.web-deployer/META-INF/jboss-service.xml by setting the attribute UseJK to true, which will say jboss to use Mod_jk. Also modify jboss/deploy/jboss.web-deployer/server.xml to let it know the node name. Now restart all the application server and your application is under load balancing. Make sure that load balancer up and running all the time.


As the name suggest – the load balancing ensure that SLA are met and also the business continuity is maintained. However, it also expect you to run the load balancer in an environment which remains up all the time. Often that environment can consist of one small server with only Apache running on it. Often recommendation is not to install any other software on that server and keep Apache’s role to just perform load balancing.

We at Walking Tree encourage you to take advantage of Adempiere’s power and in case you need any professional support, talk to us using the contact details mentioned on our Contact Us page.

Tagged with: , , , , , ,
Posted in ADempiere, EagleRP
8 comments on “Load Balancing in Adempiere
  1. Posterita says:

    I contacted Pradeep and no answer yet

  2. Posterita says:

    CAn the author or company that wrote this article contact me alex posterita.com


  3. Posterita says:


    I would like to get in touch with the author of this article. I am looking for someone who can scale my architecture.
    Naturally, I am using Adempiere.

  4. damian says:

    oh, sorry for my bad english…

    the question is about the request and account processor, running on the servers B and C as below:

    server A – apache
    server B – adempiere application server (jboss)
    server C – adempiereapplication server (jboss)

    My apache “A” server, do the load balancing between “B” and “C” adempiere aplication servers.

    Both the B and C servers, have an out of the box Adempiere installation with your suggested modifications for load balancing, and so, they runs concurrently the account and request processors used by the system for documents and requests. Is this ok?

    i hope to be more clearly now…

    thank you!

  5. PhaniKiran says:

    Can u please elaborate the question.

  6. damian says:

    good post!

    but and about the account and request processor?

    there’s no problem on running N servers with this services at the same time?

    best regards

  7. azad says:

    excellent article!! thanks to the team!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

We Have Moved Our Blog!

We have moved our blog to our company site. Check out https://walkingtree.tech/index.php/blog for all latest blogs.

Sencha Select Partner Sencha Training Partner
Xamarin Authorized Partner
Recent Publication
%d bloggers like this: