Kshitiz Saxena

Kshitiz's Blog
Tuesday Apr 01, 2008

SIP Load-Balancer

Are you looking for load-balancer to handle SIP requests ? If yes, you have come to right place .

Brief history : Sun Communication Application Server, aka sailfin, is built over glassfish. Glassfish is  Java EE 5 based application server. And sailfin provides SIP Servlet Container based on JSR 289 over and above what is offered by Glassfish.

Sailfin not only provide containers to deploy SIP and JAVA EE 5 based applications. It is complete package with high-availability features like load-balancing and session-replication required by enterprise systems.

 To learn more about load-balancer available with sailfin, please refer to my blogs on Converged Load Balancer.

Tuesday Mar 25, 2008

Converged Load-Balancer (CLB)


Brief Overview of Converged Load-Balancer

Converged Load-Balancer, is designed to provide high-availability to applications deployed on Sun Communication Application Server, aka sailfin. It will distribute requests across the instances in cluster to increase throughput of the system. It will also fail-over request from unhealthy/inaccessible instances to healthy and available instances.

Features of Converged Load-Balancer

  1. It can handle both SIP(S) and HTTP(S) requests.
  2. It can load-balance converged application (application having web and sip components) and pure web applications
  3. It will distribute the load across healthy and available instances in cluster, thus enabling a higher throughput from the system
  4. It maintains stickiness of requests in a session to single instance till serving instance is healthy, available and enabled
  5. It will fail-over request from unhealthy/unavailable/disabled instances to instances which are healthy, available and enabled
  6. It supports round-robin and consistent-hash algorithm for load-balancing
  7. It supports Data-Centric-Rule(DCR) to extract hash-key used in consistent-hash algorithm

Deployment Topology

Converged load-balancer currently supports only self load-balancing cluster. Below figure illustrates self load-balancing topology.

Converged Load-Balancer Deployment

The above deployment contains:
  • Hardware IP sprayer : This distributes request evenly across all instances in sailfin cluster.
  • Sailfin Cluster : Sailfin cluster having converged load-balancer component.
In case user does not have Hardware IP sprayer, the request can be forwarded to any one instance in sailfin cluster. The converged load-balancer component on that instance will ensure that requests are distributed across the cluster. However that instance will be single point of failure. The presence of Hardware IP sprayer ensures high availability.

Note : Sailfin does not support two-tier deployment as of now. However there is no such restriction put on admin commands. User can still create two tier deployment using admin commands. Two-tier deployment may not function correctly.

Functioning of Converged Load-Balancer

Below illustration depicts the functioning of converged load-balancer

 

CLB Functionality
  • Step 1 : Client request comes to IP Sprayer
  • Step 2 : IP sprayer selects any of the sailfin instances in the cluster and forwards request to that instance, which in above illustration is instance X.
  • Step 3 : CLB on Instance X based on configured algorithm selects an instance to service the request. Then it forward the request to that instance, which in above illustration is instance Y. This can be same instance, i.e. instance X, as well. In such case Step 3 and 4 are bypassed.
  • Step 4 : CLB on Instance Y receives the request. It finds out that request is already proxied from another instance. Without any further processing, it passes the request to the container so that it can be serviced. CLB then sends the response back to CLB on Instance X.
  • Step 5 : CLB on Instance X in turn sends the response back to IP sprayer
  • Step 6 : IP sprayer sends the response back to the client

Algorithms

Converged load-balancer currently supports two load-balancing algorithm
  1. Round-robin : Instance to service new request are selected in a round robin fashion. 
  2. Consistent-hash : Instance to service new request is selected based on hash-key extracted from request.
In both cases, once a session is established, sticky information is set on response. Subsequent requests will have that sticky information. Thus subsequent requests part of same session will stick to same instance.

There are two possible configuration:
  • Configuration 1: This can be used when there are pure web application and pure sip application deployed on the application server. There are no converged-application deployed on the application server.
    • Round-robin algorithm for http request
    • Consistent-hash algorithm for sip request. The hash-key used to select instance is extracted using from-tag,to-tag,call-id parameters of the request
  • Configuration 2: This should be used when converged applications are deployed on the application server. The user must provide a dcr-file in this case. As soon as dcr file is provided, consistent hash algorithm is used for both http and sip requests.
    • Consistent-hash algorithm for http request
      • If any dcr rule matches http request, hash-key is extracted using that rule
      • If none of the rules matches http request, hash key is extracted using remote host and port of the http request
    • Consistent-hash algorithm for sip request
      • If any dcr rule matches sip request, hash-key is extracted using that rule
      • If none of the rules matches sip request, hash key is extracted using from-tag,to-tag,call-id parameters of the sip request

Note : For complete details of converged load-balancer, please go through functional specifications of converged load-balancer.

How to configure converged load-balancer

Some common points to remember before a user start with configuration of converged load-balancer
  1. The converged load-balancer uses xml file converged load-balancer xml to get cluster information. If this file is not present, CLB will not initialize and will return error. The request will not be serviced.
  2. The converged load-balancer xml is generated when auto-commit attribute of converged-load-balancer element under availability-service is set to true. Till it set to false, no xml file is generated.
  3. It is recommended that attribute auto-commit should be set to true, once user is done with complete configuration of cluster. This includes instances creation and application deployment. Otherwise it will result in unnecessary reconfiguration with any change to cluster.
  4. It is recommended to start cluster after auto-commit is set to true and all cluster configuration is done. Please refer to point 1 above to understand why this is recommended.
  5. Only instances with lb-enabled attribute set to true will participate in load-balancing. The disabled instances are not considered for load-balancing. The command to enable/disable instance is still not available. It will be provided shortly. Till then user can do it using set command. Any new instance created in cluster will have lb-enabled set to false. User has to set this attribute to true.
  6. The cluster heartbeat-enabled attribute must be set to true. This is set to true by default, when user creates a cluster.

Using default-cluster

A default-cluster already exists in the domain created using cluster profile. The default-cluster is pre-configured as self load-balancing cluster. User has to just create instances and deploy applications and a self load-balancing cluster is ready for use. Please follow steps below :
  1. User must ensure that all instances are created in cluster and all applications are deployed to cluster. This is not a mandatory step. However this is a recommended step.
  2. Set lb-enabled attribute for all instances of default-cluster to true
    • Command : asadmin> set default-cluster.server-ref.<instance-name>.lb-enabled=true
  3. Set auto-commit attribute to true
    • Command : asadmin > set default-cluster.availability-service.converged-load-balancer.auto-commit=true
  4. Start default-cluster. If it was already running, it will now have working converged load-balancer. There is no need to restart the cluster

Creating converged-load-balancer on already existing cluster

The converged-load-balancer element does not exist under cluster config and user is starting afresh with converged load-balancer configuration. Please follow steps below :

Option 1 : A single step process
  1. User must ensure that all instances are created in cluster and all applications are deployed to cluster. This is not a mandatory step. However this is a recommended step.
  2. Create converged load-balancer using a single command
    • Command : asadmin > create-converged-lb --target <cluster-name> --autocommit=true --selfloadbalance=true --lbenableallinstances=true --configfile <converged-load-balancer-xml> <converged-load-balancer-name>
  3. Start the cluster. If cluster was already running, please restart the cluster.
Option 2 : Multi-step process with details about what exactly happens in background with Option 1
  1. User must ensure that all instances are created in cluster and all applications are deployed to cluster. This is not a mandatory step. However this is a recommended step.
  2. Create a converged load-balancer config
    • Command : asadmin> create-converged-lb-config <clb-config-name>
    • For example : asadmin> create-converged-lb-config test-clb-config
  3. Create a converged load-balancer reference to the cluster
    • Command : asadmin> create-converged-lb-ref --clbconfig  <clb-config-name>  --lbenableallinstances <cluster-name>
    • For example : asadmin> create-converged-lb-ref --clbconfig  test-clb-config  --lbenableallinstances test-cluster
  4. Create converged load-balancer for the cluster
    • Command : asadmin> create-converged-lb --clbconfig <clb-config-name> --configfile <converged-load-balancer-xml-for-cluster> --autocommit=true --target <cluster-name> <converged-load-balancer-name>
    • For example : asadmin> create-converged-lb --clbconfig test-clb-config --configfile converged-load-balancer.xml --autocommit=true --target test-cluster test-cluster-clb
  5. Start the cluster. If cluster was already running, please restart the cluster.
Note:
  1. The above command does not show the default options to be provided with each command, for example user name, password file etc.
  2. Above mentioned way of configuration is just one way of configuring converged load-balancer. The used commands has many more options. Please look at man page of each command for all possible options.


Data Centric Rules(DCR)

Data centric rules are used extract the hash-key from the request. The extracted hash-key is used to select an instance to service the request under consistent-hash algorithm.

Sample DCR file

Below is a sample DCR file :
<?xml version="1.0" encoding="ISO-8859-1"?>
<user-centric-rules>
    <sip-rules>
        <if>
            <session-case>
                <equal>ORIGINATING</equal>
                <if> 
                    <header name="ConferenceName"
                            return="request.ConferenceName">
                        <exist/>
                    </header>  
                </if>
            </session-case>
        </if>
    </sip-rules>
    <http-rules> 
        <request-uri parameter="ConferenceName" return="parameter.ConferenceName">
            <exist/>
        </request-uri>
    </http-rules>  
</user-centric-rules>

Above sample DCR file define following rules :
  1. For SIP(S) request, for an originating request look for header named ConferenceName, and value of that header will be used as hash key.
  2. For HTTP(S) request, look for parameter named ConferenceName, and value of that parameter will be used as hash key.

Configuring DCR 

A user can setup DCR in following manner :
  1. At the time of converged load-balancer creation using a single command.
    • Command : asadmin > create-converged-lb --target <cluster-name> --autocommit=true --selfloadbalance=true --lbenableallinstances=true --configfile <converged-load-balancer-xml> --dcrfile <dcr-file-name> <converged-load-balancer-name>
  2. At the time of converged load-balancer config creation
    • Command : asadmin> create-converged-lb-config --dcrfile <dcr-file-name> <clb-config-name>
  3. After creation of converged load-balancer config
    • Command :  asadmin> set-dcr-file --dcrfile <dcr-file-name> <clb-config-name>
Note:
  1. The above command does not show the default options to be provided with each command, for example user name, password file etc.

Tuesday Apr 10, 2007

Connection Leak Tracing

Does your application suffer from connection starvation? Worked long and hard on your application  to get rid of such issues but in vain . Ever wondered what is eating up all the connections. Unable to figure out whether it is your application or someone-else's . Now you have an option in glassfish v2 to trace out all such cases of connection leaks . The new connection leak tracing feature not only provides information of connection leaks, it also allows a user to reclaim leaking connections to make it available for other applications.

Now on a more technical front a brief description of the feature is provided, and how to configure, monitor and view the connection leaks.


Brief Description

Lets start with the definition of connection leak. As of now the definition is kept really simple. An application is said to be leaking connection, if it acquires a connection and does not close it within specified time period. If this feature is enabled, the application server detects these potential connection leaks and dumps the leak tracing logs to server logs. Looking at the logs the user can figure out which application is leaking connection and fix the issues with application, if exists.

An additional feature of connection reclaim is also provided with connection leak tracing. This can only be enabled when connection leak tracing is turned on. If enabled, the leaking connection with be reclaimed by application server and made available to other applications accessing the connection pool. This feature should be used responsibly. The feature should not be enabled if user's application caches connection. In such cases, enabling this feature will result in unexpected behavior.

For more detailed description, please refer to the one pager.

This feature is not enabled by default. The user need to configure his/her connection pools in order to enable connection leak tracing. The steps to achieve this is provided in the next section.


How to Configure

The connection leak tracing is an advanced feature. Additional steps are needed to configure the connection leak tracing after creating a connection pool. These settings are picked up by application server dynamically. Hence no server restart is needed.

Using GUI


1. Browse to the pool. This can be jdbc(or connector) connection pool.
Browse to the Pool
2. Click on Advanced Tab of the pool
Advanced Tab
3. Provide appropriate inputs
  • Provide non-zero value for Leak Timeout to enable connection leak tracing
  • Click the check-box of Leak Reclaim if you want connection reclaim to be enabled
Provide Pool Inputs
4. Save the changes


Using CLI


1. Set a non-zero connection leak timeout value for connection pool
  • For jdbc connection pool
    • asadmin>set domain.resources.jdbc-connection-pool.<pool-name>.connection_leak_timeout_in_seconds = 300
  • For connector connection pool
    • asadmin>set domain.resources.connector-connection-pool.<pool-name>.connection_leak_timeout_in_seconds = 300
2. Enable connection leak reclaim if desired
  • For jdbc connection pool
    • asadmin>set domain.resources.jdbc-connection-pool.<pool-name>.connection-leak-reclaim = true
  • For connector connection pool
    • asadmin>set domain.resources.connector-connection-pool.<pool-name>.connection-leak-reclaim = true



Monitoring stats for connection leak tracing

The connection leak tracing data is available to the user when monitoring is enabled for that component. To enable monitoring please refer to monitoring manual. For getting connection leak stats of :
  • JDBC connection pool, set monitoring level for JDBC connection pool component to HIGH.
  • Connector connection pool, set monitoring level for JMS/Connector Service component to HIGH.
After configuring the monitoring level for component, the monitoring data can be viewed using GUI as well as CLI.

Using GUI


1. Browse to Monitor tab. Now click on Resources tab. Select your connection pool from the drop down box.
Browse to monitoring tab
2. Scroll down the page and you will find connection leak stats
Connection leak stats

Using CLI

The command to get monitoring stats related to connection leak using CLI is:
  • For jdbc/connector connection pool
    • asadmin> get -m server.resources.<pool-name>.numpotentialconnleak*
  • The stats will look like
    • server.resources.<pool-name>.numpotentialconnleak-count = 3
    • server.resources.<pool-name>.numpotentialconnleak-description = Provides a count value reflecting the number of potential connection leaks
    • server.resources.<pool-name>.numpotentialconnleak-lastsampletime = 1175495050536
    • server.resources.<pool-name>.numpotentialconnleak-name = NumPotentialConnLeak
    • server.resources.<pool-name>.numpotentialconnleak-starttime = 1175494865525
    • server.resources.<pool-name>.numpotentialconnleak-unit = Count


Viewing potential connection leak traces

The connection leak traces are dumped  to server log with WARNING as log level. So, the log level of Connector component should be at least WARNING. This is default log level for out of the box installation. To enable logging, please refer to logging manual.

It is cumbersome to search through server logs manually. A utility is already provided in application server GUI to search through logs. The steps are provided below to get connection leak traces using this utility.

1. Open the Log Search page by clicking View Log files button. It will open up a new window.
open log search page
2. Click Advanced Search on this page
Click Advanced Search
3. Provide inputs
  • Select Log Level : WARNING
  • Select Logger : javax.enterprise.resource.resourceadapter
  • Provide connection pool name in Name-Value Pairs : ConnectionPoolName=<pool-name>
  • Click Search
Provide inputs
4. If connection leak records exist, they will be displayed
Log records
5. Click on individual record to view the record in detail
Record Details
6. The complete stack trace is provided in record detail. User can browse through it and find out the application which is causing connection leaks




Archives
Links
Referrers