FastAGI server for Perl code

Team

I am a bit of a Newby with Asterisk so pardon my ignorance. I wrote an AGI Perl code for Asterisk in CentOS that checks a callerID vs an internal MySql database. I noticed the code works fine but it slows down intermittently. After a bit of research, I found out you can run FastAGI over TCP/IP (FastAGI server). I also tried to somehow insert the working code in the FastAGI_log.pl but it freezes.

I have spent quite a bit f time trying to find a Perl FastAGI server package unsuccessfully.

I did find a PHPAGI option but I would hate to learn another language (PHP) for such a simple job.

Any assistance pointing me to the right place and documentation will be appreciated.

Thanks

Mark

  1. How many invocations per second of your AGI are you observing?

  2. How large is your caller ID table and is it indexed?

  3. How often is the table updated? (Maybe something like Redis would be a better implementation?)

On a lowly Raspberry Pi 3b I get about 0.0064 seconds per invocation* (or about 150 per second) of a Perl AGI (not FastAGI) that consists of:

use Asterisk::AGI;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
1;

(meaning it forks, loads Perl, parses, reads the AGI environment and then exits.)

Maybe there is another cause of the slow down? Maybe it’s the MySQL connection?

I think a lot of people don’t use FastAGI correctly. I’ve seen implementations where the (generic) AGI server invokes scripts in separate processes for every connection AND running the server on the same host as the Asterisk server. This does not distribute the load across servers nor eliminate the parsing and ‘compiling’ of the scripting language.

Another course of action would be to re-write your AGI in a compiled language like C or go.

If you decide to go down the FastAGI path, have you seen Asterisk::FastAGI Module? (First Google result for ‘asterisk fastagi server in perl script example.’)

If you’re observing a huge number of invocations per second and you write a task specific FastAGI server avoiding the ‘fork/load/parse’ overhead and the MySQL connection overhead, you could see a huge improvement.

*) Note that these are sequential invocations. In a ‘real world’ environment the invocations would be distributed across cores.

Thanks for your quick response seadwards

You are correct, I just noticed the delay issues might have been a result of something else since the code runs fine now. I still would like to implement FastAGI at some point, but frameworks like CPAN: Asterisk-FastAGI (URL you referenced), do not provide a clear path for installation.
In any case, I really appreciate your feedback.

Thanks again!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.