Understanding what's causing load/CPU spike

Hi,

I use MusicOnHold + Realtime extensively with Asterisk. Since I am using realtime once a class is added it stays in memory until I un-regiser the MOH class. To do this I added to the dialplan a script that checks if there is anyone else listening to this class. If they are not it connects to the Asterisk CLI and unregsiterd the class. In my Dialplan I have
System(/opt/dovid/radio/check_moh_class.sh ${MOH_ID}&)
The script has in it

CALLS=$(/usr/sbin/asterisk -rx'core show channels concise' | grep WaitDigit | grep moh_$1 |wc -l)
if [ "$CALLS" -eq "0" ]; then
asterisk -rx"moh unregister class $1"
exit;
fi

I have been having random CPU and load spikes on my boxes and I was never able to figure out why. Today I was manually hanging up on a bunch of calls (about 75 calls) and this was invoked once per call. The audio quality became horrible and I saw that the load and CPU usage spiked. I did this test a few time and every time I got the same result. I have since changed over to a script that connects via the AMI and checks every 60 sesconds all calls and see’s if there are any classes that can be unregistered.

I am writing this question more to understand what I was doing that was causing Asterisk to spike the load on the box so I can further learn.

Is Asterisk showing high CPU usage or is the system overall showing high CPU usage? What does ‘top’ show during this high CPU time?

what type music on hold are using ?

I solved this kind of issue by moving to playlist

When the hangups are happening the load goes up as well as the CPU usage.

I am playing online media streams like from shoutcast servers.

if you are using the custom type that is a known issue.

(the reason i do not know the symptom is the described.)

try the new type playlist

in the file you could set to a url for streaming i think

it should work better to my experience

Any idea what the issue is or how the symptoms are described?