Load-Balancer Module

Bogdan-Andrei Iancu

   Voice Sistem SRL

Edited by

Bogdan-Andrei Iancu

   Copyright  2009 voice-system.ro
   Revision History
   Revision $Revision: 4473 $ $Date: 2008-07-12 00:16:22 +0300
                              (Sat, 12 Jul 2008) $
     __________________________________________________________

   Table of Contents

   1. Admin Guide

        1.1. Overview
        1.2. How it works
        1.3. Dependencies

              1.3.1. OpenSIPS Modules
              1.3.2. External Libraries or Applications

        1.4. Exported Parameters

              1.4.1. db_url (string)
              1.4.2. db_table (string)

        1.5. Exported Functions

              1.5.1. load_balance(grp,resources)

        1.6. Exported statistics
        1.7. Exported MI Functions

              1.7.1. lb_reload
              1.7.2. lb_resize
              1.7.3. lb_list

        1.8. Exported pseudo-variables

   2. Developer Guide

        2.1. Available Functions

   3. Frequently Asked Questions

   List of Examples

   1.1. Set db_url parameter
   1.2. Set db_table parameter
   1.3. set_dlg_profile usage

Chapter 1. Admin Guide

1.1. Overview

   The Load-Balancer module comes to provide traffic routing based
   on load. Shortly, when OpenSIPS routes calls to a set of
   destinations, it is able to keep the load status (as number of
   ongoing calls) of each destination and to choose to route to
   the less loaded destination (at that moment). OpenSIPS is aware
   of the capacity of each destination - it is preconfigured with
   the maximum load accepted by the destinations. To be more
   precise, when routing, OpenSIPS will consider the less loaded
   destination not the destination with the smallest number of
   ongoing calls, but the destination with the largest available
   slot.

1.2. How it works

   Please refer to the Load-Balancer tutorial from the OpenSIPS
   website:
   http://www.opensips.org/index.php?n=Resources.DocsTutLoadbalanc
   ing.

1.3. Dependencies

1.3.1. OpenSIPS Modules

   The following modules must be loaded before this module:
     * Dialog - Dialog module
     * database - one of the DB modules

1.3.2. External Libraries or Applications

   The following libraries or applications must be installed
   before running OpenSIPS with this module loaded:
     * None.

1.4. Exported Parameters

1.4.1. db_url (string)

   The URL pointing to the database where the load-balancing rules
   are stored.

   Default value is "mysql://opensips:opensipsrw@localhost/osips".

   Example 1.1. Set db_url parameter
...
modparam("load_balancer", "db_url", "dbdriver://username:password@dbhost
/dbname")
...

1.4.2. db_table (string)

   The name of the DB table containing the load-balancing rules.

   Default value is "load_balancer".

   Example 1.2. Set db_table parameter
...
modparam("", "db_table", "lb")
...

1.5. Exported Functions

1.5.1.  load_balance(grp,resources)

   The function performs load-balancing over the available
   destinations in order to find the less loaded destination that
   can provide the requested resources and belong to a requested
   group.

   Meaning of the parameters is as follows:
     * grp - group id for the destinations; the destination may be
       grouped in several groups you can you for differnet
       scenarios.
     * resources - string containing a semi-colon list of
       resources required by the current call.

   Function returns true is a new destination URI is set pointing
   to the selected destiantion. NOTE that the RURI will not be
   changed by this function.

   This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
   REPLY_ROUTE and FAILURE_ROUTE.

   Example 1.3. set_dlg_profile usage
...
if (load_balance("1","trascoding;conference")) {
        # dst URI points to the new destination
        xlog("sending call to $du\n");
        t_relay();
        exit;
}
...

1.6. Exported statistics

   NONE

1.7. Exported MI Functions

1.7.1. lb_reload

   Trigers the reload of the load balancing data from the DB.

   MI FIFO Command Format:
                :lb_reload:_reply_fifo_file_
                _empty_line_

1.7.2. lb_resize

   Changes the capacity for a resource of a destination. The
   function receives as parameters the ID (as per DB) of the
   destination along with the name of the resource you want to
   resize.

   MI FIFO Command Format:
                :lb_resize:_reply_fifo_file_
                11   /*dstination id*/
                voicemail  /*resource name*/
                56   /* new resource capacity*/
                _empty_line_

1.7.3. lb_list

   Lists all the destinations and the maximum and current load for
   each resource of the destination.

   MI FIFO Command Format:
                :lb_list:_reply_fifo_file_
                _empty_line_

1.8. Exported pseudo-variables

   NONE

Chapter 2. Developer Guide

2.1. Available Functions

   NONE

Chapter 3. Frequently Asked Questions

   3.1.

       Where can I find more about OpenSIPS?

       Take a look at http://www.opensips.org/.

   3.2.

       Where can I post a question about this module?

       First at all check if your question was already answered on one
       of our mailing lists:
         * User Mailing List -
           http://lists.opensips.org/cgi-bin/mailman/listinfo/users
         * Developer Mailing List -
           http://lists.opensips.org/cgi-bin/mailman/listinfo/devel

       E-mails regarding any stable OpenSIPS release should be sent to
       <users@lists.opensips.org> and e-mails regarding development
       versions should be sent to <devel@lists.opensips.org>.

       If you want to keep the mail private, send it to
       <users@lists.opensips.org>.

   3.3.

       How can I report a bug?

       Please follow the guidelines provided at:
       http://sourceforge.net/tracker/?group_id=232389.
