views:

357

answers:

3

I am writing multiple AGIs using Perl that will be called from the Asterisk dialplan. I expect to receive numerous similtaneous calls so I need a way to load balance them. I have been advised to use FastAGI instead of AGI. The problem is that my AGIs will be distributed over many servers not just one, and I need that my entry point Asterisk dispatches the calls among those servers (where the agis reside) based on their availability. So, I thought of providing the FastAGI application with multiple IP addresses instead of one. Is it possible?

A: 

I have a large IVR implementation using FastAGI (24 E1's all doing FastAGI calls, peaks at about 80% so that's nearly 600 Asterisk channels calling FastAGI). I didn't find an easy way to do load balancing, but in my case there are different FastAGI calls: one at the beginning of the call to validate the user in a database, then a different one to check the user's balance or their most recent transactions, and another one to perform a transacion.

So what I did was send all the validation and simple queries to one application on one server and all the transaction calls to a different application on a different server.

A crude way to do load balancing if you have a lot of incoming calls on zaptel/dahdi channels would be to use different groups for the channels. For example suppose you have 2 FastAGI servers, and 4 E1's receiving calls. You can set up 2 E1's in group g1 and the other 2 E1's in group g2. Then you declare global variables like this:

[globals]
serverg1=ip_of_server1
serverg2=ip_of_server2

Then on your dialplan you call FastAGI like this:

AGI(agi://${server${CHANNEL(callgroup)}}/some_action)

On channels belonging to group g1, that will resolve to serverg1 which will resolve to ip_of_server1; on channels belonging to group g2, CHANNEL(callgroup) will resolve to g2 so you get ${serverg2} which resolves to ip_of_server2.

It's not the best solution because usually calls start coming in on one span and then another, etc so one server will get more work, but it's something.

To get real load balancing I guess we would have to write a FastAGI load balancing gateway, not a bad idea at all...

Chochos
A: 

Thank you chochos for the reply. I am using softphones in my case so I do not know if your solution would be applicable in my case. Also how do you define groups and how do you associate channels to these groups?

A: 

Mehhh... use the same constructs that would apply to load balancing something like web page requests.

One way is to round robin in DNS. So if you have vru1.example.com 10.0.1.100 and vru2.example.com 10.0.1.101 you put two entries in DNS like...

fastagi.example.com 10.0.1.100

fastagi.example.com 10.0.1.101

... then from the dial plan agi(agi://fastagi.example.com/youagi) should in theory alternate between 10.0.1.100 and 10.0.1.101. And you can add as many hosts as you need.

The other way to go is with something a bit too complicated to explain here but proxy tools like HAProxy should be able to route between multiple servers with the added benefit of being able to "take one out" of the mix for maintenance or do more advanced balancing like distribute equally based on current load.

vbcrlfuser