Scaling basically means that if the hardware in your system can’t handle any more load, then the system should be able to take additional hardware and share extra load with it. In case of VoIP calls, if you server is capable of handling, lets say 300 concurrent calls, and thanks to your evolving business now your call volume is going beyond 300 concurrent calls, then adding an additional server should take these additional calls and this way share the load of this extra call volume.
There are various ways to scale any system. In case of an Asterisk server, we can scale it simply in its dialplan by defining additional trunks to use in case the traffic volume is more than usual.
Lets say we have two asterisk servers: Asterisk-A and Asterisk-B. We can connect them using both IAX and SIP trunks. It is very simple to do. I prefer to use IAX trunking between the asterisk servers, because this is what this protocol is designed for (IAX – Inter Asterisk eXchange).
For the sake of this example, we’ll assume that Asterisk-A has IP address 192.168.0.10 and Asterisk-B has IP address 192.168.0.11. The context which processes the calls is named [main-context]. Communication takes place over ulaw.
Create the following context in iax.conf on Asterisk A:
[mytrunk]
host=192.168.0.11
type=friend
qualify=yes
trunk=yes
disallow=all
allow=ulaw
context=main-context
Now create the following context in iax.conf on Asterisk B:
[mytrunk]
host=192.168.90.10
type=friend
qualify=yes
trunk=yes
disallow=all
allow=ulaw
context=main-context
The only difference in the above is that of the IP addresses.
Now reload IAX on both the servers, from asterisk CLI:
iax2 reload
Once done, you can see the status of these trunks using:
iax2 show peers
iax2 show users
These command will show the status of these trunks like this:
Asterisk-A*CLI> iax2 show peers
Name/Username Host Mask Port Status
trunkb 192.168.0.11 (S) 255.255.255.255 4569 (T) OK (2 ms)
1 iax2 peers [1 online, 0 offline, 0 unmonitored]
Asterisk-A*CLI> iax2 show users
Username Secret Authen Def.Context A/C Codec Pref
trunkb -no secret- 000000000000003 main-context No Host
This means that the trunks are ready for use.
Taking into account that Asterisk-A is the primary server which is receiving and sending calls, now in the dialplan you can introduce a condition so that if the number of calls is greater than 300, direct them to Asterisk-B. For example if NUMCALLS is the variable keeping track of the active calls, and the name of your default trunk is ‘main-trunk’, you can do the following:
(AEL example)
Set(TRUNK=”main-trunk”);
if(“${NUMCALLS}”>”300″) { Set(TRUNK=”mytrunk”); };
Dial(SIP/${TRUNK}/${EXTEN});
(non-AEL example)
exten => _.,1,Set(TRUNK=”main-trunk”)
exten => _.,n,GotoIf($["${NUMCALLS}">"300"]?scale:noscale)
exten => _.,n(scale),Set(TRUNK=”mytrunk”)
exten => _.,n(noscale),Dial(SIP/${TRUNK}/${EXTEN});
To learn how to setup a variable like NUMCALLS to keep track of your active calls, see my blog ”Keep track of number of active calls in Asterisk”, which has its link in the list below.
1 person likes this post.
Unlike
Recent Comments