Categories
Asterisk Kamailio Voice over IP

Kamailio Bytes – Gotchas with Kamailio as an Asterisk Load Balancer

Things to keep in mind before using Kamailio as a Load Balancer for Asterisk

How do I make Kamailio work with Asterisk?

It’s a seemingly simple question, the answer to which is – however you want, sorry if that’s not a simple answer.

I’ve talked about the strengths and weaknesses of Kamailio and Asterisk in my post Kamailio vs Asterisk, so how about we use them to work together?

The State of Play

So before we go into the nitty gritty, let’s imagine we’ve got an Asterisk box with a call queue with Alice and Bob in it, set to ring those users if they’re not already on a call.

Each time a call comes in, Asterisk looks at who in the queue is not already on a call, and rings their phone.

Now let’s imagine we’re facing a scenario where the single Asterisk box we’ve got is struggling, and we want to add a second to share the load.

We do it, and now we’ve got two Asterisk boxes and a Kamailio load balancer to split the traffic between the two boxes.

Now each time a call comes in, Kamailio sends the SIP INVITE to one of the two Asterisk boxes, and when it does, that Asterisk box looks at who is in the queue and not already on a call, and then rings their phone.

Let’s imagine a scenario where a Alice & Bob are both on calls on Asterisk box A, and another call comes in this call is routed to Asterisk box B. Asterisk box B looks at who is in the queue and who is already on a call, the problem is Alice and Bob are on calls on Asterisk box A, so Asterisk box B doesn’t know they’re both on a call and tries to ring them.

We have a problem.

Scaling stateful apps is a real headache,

So have a good long hard think about how to handle these issues before going down this path!

3 replies on “Kamailio Bytes – Gotchas with Kamailio as an Asterisk Load Balancer”

Saving state is necessary in such case. It should be fast. The answer (usually) is Redis. Another option could be changing Asterisk to Freeswitch, which performs slightly better and could save of the need to put second server online.

Well, an idea in multitenant environments is to deliver all traffic from a particular tenant to a single asterisk box, and also forward the dids to that box. So every customer has is own tenantID and uses this as sip account. You can then easily split traffic in Kamailio per tenant to multiple boxes. Unless you have a really large client with more 1000 extensions.

Hey Bram,
The problem with just using Asterisk to distribute load for different tenants to a respective Asterisk box is it doesn’t scale super well as you mentioned – I find in the past I didn’t even get near 1000 extensions if they were heavy users like Contact Center agents.

Leave a Reply to MK Cancel reply

Your email address will not be published. Required fields are marked *