How many invocations per second of your AGI are you observing?
How large is your caller ID table and is it indexed?
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:
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
(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.