|
Resources -> Documentation -> Tutorials -> Load BalancingThis page has been visited 32309 times. Table of Content (hide) 1. Load Balancing in OpenSIPSThe "load-balancing" 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. Also, the "load-balancing" (LB) module is able to receive feedback from the destinations (if they are capable of). This mechanism is used for notifying OpenSIPS when the maximum capacity of a destination changed (like a GW with more or less E1 cards). The "load-balancing" functionality comes to enhance the "dispatcher" one. The difference comes in having or not load information about the destinations where you are routing to:
A Workshop on this topic was held at Amoocon (former AsteriskTag) in Rostock, 4-5 May 2009 2. Load Balancing - how it worksWhen looking at the LB implementation in OpenSIPS, we have 3 aspects: 2.1 Destination setA destination is defined by its address (a SIP URI) and its description as capacity. Form the LB module perspective, the destinations are not homogeneous - they are not alike; and not only from capacity point of view, but also from what kind of services/resources they offer. For example, you may have a set of Yate/Asterisk boxes for media-related services -some of them are doing transcoding, other voicemail or conference, other simple announcement , other PSTN termination. But you may have mixed boxes - one box may do PSTN and voicemail in the same time. So each destination from the set may offer a different set of services/resources. So, for each destination, the LB module defines the offered resources, and for each resource, it defines the capacity / maximum load as number of concurrent calls the destination can handle for that resource. Example:
4 destinations/boxes in the LB set
1) offers 30 channels for transcoding and 32 for PSTN
2) offers 100 voicemail channels and 10 for transcoding
3) offers 50 voicemail channels and 300 for conference
4) offers 10 voicemail, 10 conference, 10 transcoding and 32 PSTN
This translated into the following setup:
+----+----------+------------------------+---------------------------------+
| id | group_id | dst_uri | resources |
+----+----------+------------------------+---------------------------------+
| 1 | 1 | sip:yate1.mycluset.net | transc=30; pstn=32 |
| 2 | 1 | sip:yate2.mycluset.net | vm=100; transc=10 |
| 3 | 1 | sip:yate3.mycluset.net | vm=50; conf=300 |
| 4 | 1 | sip:yate4.mycluset.net | vm=10;conf=10;transc=10;pstn=32 |
+----+----------+------------------------+---------------------------------+
For runtime, the LB module provides MI commands for:
2.2 Invoking Load-balancingUsing the LB functionality is very simple - you just have to pass to the LB module what kind of resources the call requires. The resource detection is done in the OpenSIPS routing script, based on whatever information is appropriated. For example, looking at the RURI (dialed number) you can see if the call must go to PSTN or if it a voicemail or conference number; also, by looking at the codecs advertised in the SDP, you can figure out if transcoding is or not also required.
if (!load_balance("1","transc;pstn")) {
sl_send_reply("500","Service full");
exit;
}
The first parameter of the function identifies the LB set to be used (see the group_id column in the above DB snapshot). Second parameter is list of the required resource for the call. The load_balance() will automatically create the dialog state for the call (in order to monitor it) and will also allocate the requested resources for it (from the selected box). The resources will be automatically released when the call terminates. The LB module provides an MI function that allows the admin to inspect the current load over the destinations. 2.3 The LB logicThe logic used by the LB module to select the destination is:
Example:
4 destinations/boxes in the LB set
1) offers 30 channels for transcoding and 32 for PSTN
2) offers 100 voicemail channels and 10 for transcoding
3) offers 50 voicemail channels and 300 for conference
4) offers 10 voicemail, 10 conference, 10 transcoding and 32 PSTN
when calling load_balance("1","transc;pstn") ->
1) only boxes (1) and (4) will be selected at as they offer both transcoding and pstn
2) evaluating the load :
(1) transcoding - 10 channels used; PSTN - 18 used
(4) transcoding - 9 channels used; PSTN - 16 used
evaluating available load (capacity-load) :
(1) transcoding - 20 channels used; PSTN - 14 used
(4) transcoding - 1 channels used; PSTN - 16 used
3) for each box, the minimum available load (through all resources)
(1) 14 (PSTN)
(2) 1 (transcoding)
4) final selected box in (1) as it has the the biggest (=14) available load for the most loaded resource.
The selection algorithm tries to avoid the intensive usage of a resource per box. 3. Study Case: routing the media gatewaysHere is the full configuration and script for performing LB between media peers. 3.1 ConfigurationLet's consider the case previously described:
4 destinations/boxes in the LB set
1) offers 30 channels for transcoding and 32 for PSTN
2) offers 100 voicemail channels and 10 for transcoding
3) offers 50 voicemail channels and 300 for conference
4) offers 10 voicemail, 10 conference, 10 transcoding and 32 PSTN
This translated into the following setup:
+----+----------+------------------------+---------------------------------+
| id | group_id | dst_uri | resources |
+----+----------+------------------------+---------------------------------+
| 1 | 1 | sip:yate1.mycluset.net | transc=30; pstn=32 |
| 2 | 1 | sip:yate2.mycluset.net | vm=100; transc=10 |
| 3 | 1 | sip:yate3.mycluset.net | vm=50; conf=300 |
| 4 | 1 | sip:yate4.mycluset.net | vm=10;conf=10;transc=10;pstn=32 |
+----+----------+------------------------+---------------------------------+
3.2 OpenSIPS Scripting
debug=1
memlog=1
fork=yes
children=2
log_stderror=no
log_facility=LOG_LOCAL0
disable_tcp=yes
disable_dns_blacklist = yes
auto_aliases=no
check_via=no
dns=off
rev_dns=off
listen=udp:xxx.xxx.xxx.xxx:5060
loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/sl/sl.so"
loadmodule "modules/db_mysql/db_mysql.so"
loadmodule "modules/tm/tm.so"
loadmodule "modules/xlog/xlog.so"
loadmodule "modules/uri/uri.so"
loadmodule "modules/rr/rr.so"
loadmodule "modules/dialog/dialog.so"
loadmodule "modules/mi_fifo/mi_fifo.so"
loadmodule "modules/mi_xmlrpc/mi_xmlrpc.so"
loadmodule "modules/signaling/signaling.so"
loadmodule "modules/textops/textops.so"
loadmodule "modules/load_balancer/load_balancer.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("dialog", "dlg_flag", 13)
modparam("dialog", "db_mode", 1)
modparam("dialog", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
modparam("rr","enable_double_rr",1)
modparam("rr","append_fromtag",1)
modparam("load_balancer", "db_url","mysql://opensips:opensipsrw@localhost/opensips")
route{
if (!mf_process_maxfwd_header("3")) {
sl_send_reply("483","looping");
exit;
}
if (!has_totag()) {
# initial request
record_route();
} else {
# sequential request -> obey Route indication
loose_route();
t_relay();
exit;
}
# handle cancel and re-transmissions
if ( is_method("CANCEL") ) {
if ( t_check_trans() )
t_relay();
exit;
}
# from now on we have only the initial requests
if (!is_method("INVITE")) {
send_reply("405","Method Not Allowed");
exit;
}
# detect resources and do balancing
if ($rU=~"^1") {
# looks like a Conference call
load_balance("1","conf");
} else if ($rU=~"^2") {
# looks like a VoiceMail call
load_balance("1","vm");
} else {
# PSTN call, but the GWs supports only G711
# for calls without G711, transcoding will be used on the GW
if ( !search_body("G711") ) {
load_balance("1","transc;pstn");
} else {
load_balance("1","pstn");
}
}
# LB function returns negative if no suitable destination (for requested resources) is found,
# or if all destinations are full
if ($retcode<0) {
sl_send_reply("500","Service full");
exit;
}
xlog("Selected destination is: $du\n");
# send it out
if (!t_relay()) {
sl_reply_error();
}
}
4. Comments
| News OpenSIPS LiveDVD04th of August 2010
OpenSIPS Virtual Machine is now available ... OpenSIPS 1.6.302nd of August 2010
OpenSIPS 1.6.3 major release gets better... OpenSIPS @ ClueCon29th of July 2010
OpenSIPS 2.0 @ ClueCon 2010. OpenSIPS eBootcamp12th of July 2010
Remote OpenSIPS learning with Ebootcamp program. OpenSIPS @ Amoocon 20104th of May 2010
OpenSIPS had 2 papers at Amoocon 2010. SIMPLE Aggregation14th of April 2010
Presence and BLF state aggregation. OpenSIPS Certified Professional13th of April 2010
OpenSIPS certification program launched. OpenSIPS webinar30th of March 2010
Next webinars is Variables in OpenSIPS scripting OpenSIPS 1.6.211th of March 2010
OpenSIPS 1.6.2 is brings new features... OpenSIPS Control Panel 4.008th of March 2010
OpenSIPS CP 4.0 comes with user provisioning... Conference on "OpenSIPS 2.0"5th of March 2010
VoIP Users Conference will host an audio conference OpenSIPS webinar25th of February 2010
Next webinars is Explaining the default script OpenSIPS 2.0 Design15th of February 2010
Design of OpenSIPS 2.0 is unveiled OpenSIPS webinar28th of January 2010
Next OpenSIPS webinars is SIP Introduction Building Telephony Systems with OpenSIPS 1.621st of January 2010
New edition is available... OpenSIPS 1.6.1 is released21st of December 2009
OpenSIPS 1.6.1 minor release is out... OpenSIPS Development Course17th of December 2009
OpenSIPS Devel Course for 2010... OpenSIPS Bootcamps 201009th of December 2009
2010 Schedule for Bootcamp events... User Location is faster13th of November 2009
USRLOC is 3 time faster than before... OpenSIPS Control Panel 3.030th of October 2009
OpenSIPS CP 3.0 major release is out... OpenSIPS 1.6.0 is released16th of October 2009
OpenSIPS 1.6.0 major release is out... OpenSIPS VoIP Service21th of September 2009
OpenSIPS project offers free VoIP services... OpenSIPS & Astricon21th of September 2009
OpenSIPS talks and exhibits at Astricon 2009... SVN freeze17th of September 2009
SVN trunk gets frozen to prepare 1.6 release... New types of script routes10th of September 2009
New additions to configuration file routes... STUN server7th of September 2009
OpenSIPS has now a built-in STUN server... Pseudovariable implementation extended3rd of September 2009
Added new operations for pvars to give more power to the script writer... OpenSIPS Asterisk Integration30th of August 2009
Tutorial for realtime integration... OpenSIPS 1.5.3 is released27th of August 2009
OpenSIPS 1.5.3 minor release is out... AAA and RADIUS support18th of April 2009
New AAA API and RADIUS enhancements in OpenSIPS OpenSIPS webinar4th of April 2009
Next OpenSIPS webinars is Types of Routs in OpenSIPS B2BUA3rd of August 2009
A B2BUA signaling implementation in OpenSIPS DB virtual23th of July 2009
A DB conn mixer for failover, parallel and LB Codec manipulation23th of July 2009
SDP codecs and priorities manipulation Memcached interfacing16th of July 2009
memcached support for memory caching API OpenSIPS 1.5.2 is released15th of July 2009
OpenSIPS 1.5.2 minor release is out... OpenSIPS@ClueCon14th of July 2009
OpenSIPS talks at ClueCon OpenSIPS webinar30th of June 2009
Next OpenSIPS webinars is Routing in SIP REGISTRAR enhancements29th of June 2009
REGISTRAR module becomes more flexible OpenSIPS free webinars01st of June 2009
OpenSIPS webinars program was launched OpenSIPS-CP 2.0 is released13rd of April 2009
OpenSIPS Control Panel 2.0 major release is out... OpenSIPS 1.5.1 is released13rd of April 2009
OpenSIPS 1.5.1 minor release is out... OpenSIPS 1.5.0 is released23rd of March 2009
OpenSIPS 1.5.0 major release is out... OpenSIPS 1.4.5 is released23rd of March 2009
OpenSIPS 1.4.5 minor release is out... OpenSIPS as Load Balancer4th of March 2009 OpenSIPS at Amoocon (AsteriskTAG)24th of February 2009 |