如何负载平衡 FastAGI?
我正在使用 Perl 编写多个 AGI,这些 AGI 将从 Asterisk 拨号计划中调用。 我预计会同时收到大量呼叫,因此我需要一种方法来平衡它们的负载。 有人建议我使用 FastAGI 而不是 AGI。 问题是我的 AGI 将分布在许多服务器上,而不仅仅是一台,并且我需要我的入口点 Asterisk 根据这些服务器(Agi 所在的位置)的可用性在这些服务器之间分派调用。 因此,我想到为 FastAGI 应用程序提供多个 IP 地址,而不是一个。 是否可以?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何 TCP 反向代理都可以解决这个问题。 HAProxy 是一,并且 nginx 与 TCP 模块 是另一个。
不久前,我使用 node.js 制作了自己的 FastAGI 代理(nodast)来解决这个非常具体的问题以及更多问题,包括通过 SSL 运行 FastAGI 协议以及基于 AGI 请求位置和参数路由请求的能力(例如$dnis、$channel、$language,...)
此外,由于代理配置基本上是 javascript,因此您实际上可以通过非常有趣的方式进行负载平衡。
示例配置如下所示:
Any TCP reverse proxy would do the trick. HAProxy being one and nginx with the TCP module being another one.
A while back, I've crafted my own FastAGI proxy using node.js (nodast) to address this very specific problem and a bit more, including the ability to run FastAGI protocol over SSL and route requests based on AGI request location and parameters (such as $dnis, $channel, $language, ...)
Moreover, as the proxy configuration is basically javascript, you could actually load balance in really interesting ways.
A sample config would look as follow:
我有一个使用 FastAGI 的大型 IVR 实施(24 个 E1 全部执行 FastAGI 呼叫,峰值约为 80%,因此有近 600 个 Asterisk 通道呼叫 FastAGI)。 我没有找到一种简单的方法来进行负载平衡,但在我的情况下,有不同的 FastAGI 调用:一个在调用开始时验证数据库中的用户,然后另一个不同的调用来检查用户的余额或他们的最大余额最近的交易,以及另一笔要执行的交易。
因此,我所做的是将所有验证和简单查询发送到一台服务器上的一个应用程序,并将所有事务调用发送到另一台服务器上的不同应用程序。
如果 zaptel/dahdi 通道上有大量来电,则进行负载平衡的一种粗略方法是为通道使用不同的组。 例如,假设您有 2 个 FastAGI 服务器,以及 4 个 E1 接收呼叫。 您可以在 g1 组中设置 2 个 E1,在 g2 组中设置另外 2 个 E1。 然后,您可以像这样声明全局变量:
然后在您的拨号方案上,您可以这样调用 FastAGI:
在属于组 g1 的通道上,它将解析为 serverg1,后者将解析为 ip_of_server1; 在属于组 g2 的通道上,CHANNEL(callgroup) 将解析为 g2,因此您得到 ${serverg2},它解析为 ip_of_server2。
这不是最好的解决方案,因为通常呼叫开始进入一个跨度,然后进入另一个跨度,依此类推,因此一台服务器将获得更多工作,但它是重要的。
为了获得真正的负载平衡,我想我们必须编写一个 FastAGI 负载平衡网关,这不是一个坏主意......
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:
Then on your dialplan you call FastAGI like this:
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...
嗯……使用与网页请求等负载平衡相同的构造。
一种方法是 DNS 中的循环法。 因此,如果您有 vru1.example.com 10.0.1.100 和 vru2.example.com 10.0.1.101,您可以在 DNS 中放入两个条目,例如...
fastagi.example.com 10.0.1.100
fastagi.example.com 10.0.1.101
...那么从拨号计划 agi(agi://fastagi.example.com/youagi) 理论上应该在 10.0.1.100 和 10.0.1.101 之间交替。 您可以根据需要添加任意数量的主机。
另一种方法是使用一些过于复杂的东西,无法在这里解释,但像 HAProxy 这样的代理工具应该能够在多个服务器之间进行路由,并具有能够从组合中“取出一个”进行维护或执行更高级操作的额外好处平衡就像基于当前负载平均分配。
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.