VICIDIAL - LOAD BALANCING setup.

This document is meant to summarize the capabilities and setup of VICIDIAL in a multi-server environment.

Why Load Balance?

The primary reason to do load balancing, or clustering of multiple VICIDIAL servers, is to spread the calls taken in or the answered calls on an outbound campaign across all of the agents that are logged into a campaign no matter what server they are on. For instance, on an outbound campaign, you have 2 servers, server one has 20 agents logged in on a campaign and the other server(two) has 5 agents logged in on the same campaign. Lets say that the campaign is set to a dial_level of 3.0 so there are 60 active calls being placed on server one and 15 active calls being placed on server two. Then 23 of the calls on server one answer meaning that there are three calls too many for the agents available on that server. Under a load-balancing-overflow setup those three calls can travel over an IAX2 trunk directly to the agents on that server that are still available. This increased efficiency in both inbound and outbound environments as well as reducing on-hold times for customers and equalizing wait times for agents across all servers for a campaign.

Another reason for load balancing is the ability to use cheaper hardware on the server side. It is much cheaper and more fault-tolerant to buy four P4 2.0GHz 1U servers for $800 a piece than it is to buy a single 4U quad Xeon 3.2GHz server. The four 1U servers will have more total capacity, can be easily scaled and if one fails you've only lost 25% of capacity instead of everything. This philosophy has serverd our call center very well over the last two years.


How do I set up load balancing on my two server VICIDIAL setup?

These steps are taken directly from the SCRATCH_INSTALL document, but they are all put together here to give a better idea of what is needed all in one place. It is assumed that you already have VICIDIAL up and running on both servers.

NOTE: In a multi-server setup you may want to have your database and web server on a separate machine from your Asterisk/VICIDIAL servers. Simply copy the web page directories to your new database/web server and set the AST_SERVER_conf.pl files on your VICIDIAL servers to point to that new database server. You can also have several web servers(or even load-balancing web servers) if you have more than 70 seats in one installation you may want to do that. For the web pages you just need to make sure the dbconnect.php files are configured for your database server. We have had 9 VICIDIAL servers and 2 web servers using a single database server with no problems.


1. The VICIDIAL/Asterisk servers need to have all of the perl scripts and cron jobs installed on them, except these which only need to be on one of the servers: 
	- AST_VDhopper.pl
	- AST_cleanup_agent_log.pl
	- ADMIN_adjust_GMTnow_on_leads.pl
	- AST_DB_optimize.pl


2. The two servers need to be registered to each other as IAX2 friends:
  SERVER ONE(ASTtest1-10.10.10.15) 
    iax.conf:
	register => ASTtest1:test@10.10.10.16

  	[ASTtest2]
	type=friend
	accountcode=IAXtrunk2
	context=default
	auth=plaintext
	host=dynamic
	permit=0.0.0.0/0.0.0.0
	secret=test
	qualify=yes

  SERVER TWO(ASTtest2-10.10.10.16) 
    iax.conf:
	register => ASTtest2:test@10.10.10.15

  	[ASTtest1]
	type=friend
	accountcode=IAXtrunk1
	context=default
	auth=plaintext
	host=dynamic
	permit=0.0.0.0/0.0.0.0
	secret=test
	qualify=yes


3. The two servers need to have wildcard extensions assigned to the other server in the dialplan:
  SERVER ONE(ASTtest1-10.10.10.15) 
    extensions.conf:
	[globals]
	TRUNKIAX2=IAX2/ASTtest1:test@10.10.10.16

  	[default]
	exten => _010*010*010*016*8600XXX,1,Dial(${TRUNKIAX2}/${EXTEN:16},55,o)
	exten => _010*010*010*016*8600XXX,2,Hangup

  SERVER TWO(ASTtest2-10.10.10.16) 
    extensions.conf:
	[globals]
	TRUNKIAX1=IAX2/ASTtest2:test@10.10.10.15

  	[default]
	exten => _010*010*010*015*8600XXX,1,Dial(${TRUNKIAX1}/${EXTEN:16},55,o)
	exten => _010*010*010*015*8600XXX,2,Hangup


4. For BOTH servers the VDAD extens need to be setup there as well for the Load-Balance and Load-Balance-Overflow AGI scripts, as well as setting up the closer and inbound extens if needed:

	; VICIDIAL_auto_dialer transfer script Load Balance Overflow:
	exten => 8367,1,AGI(call_log.agi,${EXTEN})
	exten => 8367,2,AGI(agi-VDAD_LO_transfer.agi,${EXTEN})
	exten => 8367,3,AGI(agi-VDAD_LO_transfer.agi,${EXTEN})
	exten => 8367,4,AGI(agi-VDAD_LO_transfer.agi,${EXTEN})
	exten => 8367,5,Hangup

	; VICIDIAL_auto_dialer transfer script Load Balanced:
	exten => 8368,1,AGI(call_log.agi,${EXTEN})
	exten => 8368,2,AGI(agi-VDAD_LB_transfer.agi,${EXTEN})
	exten => 8368,3,AGI(agi-VDAD_LB_transfer.agi,${EXTEN})
	exten => 8368,4,AGI(agi-VDAD_LB_transfer.agi,${EXTEN})
	exten => 8368,5,Hangup

	; parameters for agi-VDAD_LB_closer.agi (2 fields separated by five dashes "-----"):
	; 1. the full extension formatted by VICIDIAL for internal transfers * separated
	; 2. the word START to denote the beginning of the acceptance of the transfer
	; inbound VICIDIAL transfer calls [INTERNAL TRANSFER]
	exten => _90009.,1,Answer                  ; Answer the line
	exten => _90009.,2,AGI(agi-VDAD_LB_closer.agi,${EXTEN}-----START)
	exten => _90009.,3,Hangup

	; parameters for agi-VDAD_LO_closer.agi (2 fields separated by five dashes "-----"):
	; 1. the full extension formatted by VICIDIAL for internal transfers * separated
	; 2. the word START to denote the beginning of the acceptance of the transfer
	; inbound VICIDIAL transfer calls [LOCAL TRANSFER]
	exten => _990009.,1,Answer                  ; Answer the line
	exten => _990009.,2,AGI(agi-VDAD_LO_closer.agi,${EXTEN}-----START)
	exten => _990009.,3,Hangup

	; inbound VICIDIAL call with prompt for 4-digit fronter code
	exten => 1234,1,Answer                  ; Answer the line
	exten => 1234,2,AGI(agi-VDAD_LO_closer_inbound.agi,CL_GALLERIA-----7275555134-----Closer-----park----------999-----1)
	exten => 1234,3,Hangup


5. Reload both Asterisk servers and for outbound change the VDAD exten to 8367 or 8368 and kill the AST_VDauto_dial.pl scripts on both servers so they can restart and you can now look at the AST_timeonVDADall.php page(per campaign time-on-VDAD available from the STATS and REPORTS link on the vicidial admin screen) that will allo you to see the server_ip of the agent and the server_ip of the call per campaign across all campaigns.

If you have any questions or problems please post to the astguiclient-users list(link available on the project website)

6. For multi-server VICIDIAL/astGUIclient installations these cron scripts only need to be set up and run on one of the servers:
- AST_VDhopper.pl
- AST_cleanup_agent_log.pl
- ADMIN_adjust_GMTnow_on_leads.pl
- AST_DB_optimize.pl

