[Freeswitch-users] Load balancing solution using pure FreeSWITCH
vetali100 at gmail.com
Tue Mar 16 05:04:21 PDT 2010
Hi dear FS community,
After a brief analysis of 2 solutions using OpenSIPS and Kamailio (
http://wiki.freeswitch.org/wiki/SBC_Setup) I decided to implement my own
solution using ONLY FreeSWITCH and ONLY 1 table of any database server (we
It works on few of our servers right now without any issues.
Feel free to reuse / improve it or provide your comments if you see
something wrong with it.
We have one routing server (RS) and several Media Servers (MS).
FreeSWITCH is installed on each server in default configuration.
RS --> MS_2
(Failover can be implemented by adding one more routing server, but this is
out of scope of current description).
Routing server routes calls to media servers based on logic that you can
(Generally speaking, Routing server can route part of the calls onto itself,
but to simplify let's say that it will route only to Media Servers).
Routing server is used to register subscribers (it will have directory files
Media servers do NOT contain files with users (security issue? probably
should be managed on dialplan stage of media servers by comparing ip
addresses of requests).
The whole routing can be presented by the following chain:
Call arrives into Default context-->RS default dialplan-->Lua script-->PHP
script to get destination MEDIA SERVER IP-->back to Lua script-->Bridge
"sofia/external/" to determined MS IP address-->[Bridge to fail over media
Let's say we need to route all international calls based on less loaded
server (other logic can be easily implemented in PHP script as well).
*1. RS Dialplan: default.xml*
<action application="lua" data="route.lua $2"/>
*2. RS Lua script: route.lua*
called_number = argv; //without "00"
api = freeswitch.API();
server_ip_address = api:executeString("curl
session:setVariable("bypass_media", "true"); //described below!!!
*3. PHP script: get_server_ip.php*
<<< ANY PHP CODE THAT WILL QUERY COMMON DATABASE AND WILL DETERMINE LESS
LOADED AT THE MOMENT SERVER>>>
All Media Servers should provide information about their current load into
one common database (dedicated server or routing server can be used for
If you use scripts you can update this table on starting a call and after
Or you can create a job that will query FreeSWITCH and will update the
database every, say, 10 seconds.
Basically that's all (really!)
I beleive it can be used for most general purpose scenarios without need of
The only problem we had from the beginning was that RTP media traffic was
passing thru both servers: RS and Media Server.
But after we added the following command to the routing script, RTP media
traffic started to pass only thru Media server, making RS almost free.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the FreeSWITCH-users