Music on hold (MoH) is the stream you listen when you are being transferred, or when you are in a queue. If my understanding is right, it happens that MoH is continuously reviewed and played within the FreeSWITCH. A single server with many MoH queues will be using/wasting your CPU. Here it is what I have figured out to workaround this situation.
If you have a cluster with many tenants (aka domains), and each user is able to upload its own music on hold you soon will realize that your CPU's utilization starts growing like crazy. I used to have one server in which the FreeSWITCH daemon was reported to use 30% of CPU constantly even without 1 extension registered. If I unload the mod_local_stream module, FreeSWITCH CPU utilization drops to 1%. Insane right? But it clearly tells me it has to be with MoH. Of course, I was loading 99 queues.
Here it is what I did.
Get rid of your MP3
Sadly, as far as FusionPBX 4.2, there is no way to block MP3 uploads. So, you will need to write some backend scripts to convert all your MP3 files to WAV. Although MP3 files are small compared to WAV ones, playing MP3 is CPU hungry, and because of that, I do really recommend to void them at any cost.
Place the right Sample
FreeSWITCH uses the last directory to store files by rate. For example, /usr/share/freeswitch/sound/music/inside-out.xyz/8000/ will hold my MoH at 8 kHz. It is very common some users upload files with the wrong rate. This forces FreeSWITCH to do real-time resampling, therefore it wastes your CPU.
I can share you a script I wrote for this:
Void any possible Resampling
When you create a queue, it is recommended you upload your sound sampled in the four rates FreeSWITCH may need it: 8 kHz, 16 kHz, 32 kHz and 48 kHz. The most common is 8 kHz; codecs such as g729 and the PSTN network are using the 8 kHz rate; some codecs such as g722 use the 32 kHz rate.
Unload unnecessary MoH Queues
This only applies if you are running a cluster. Usually, a load balanced cluster puts a whole customer on one server: customer A on server1, customer B on server1, customer C on server2 and so on.
FusionPBX clustering way of doing things shares a whole database to all the servers. Since release 4.2, the mod_local_stream module loads its information from the XML Handler, which it feeds from the database. Therefore, when loading this holy module, you are loading unnecessary queues. Let's say, if you are on server 1, you are also loading MoH queues of customer C which it is using another server. According to my findings, the more queues it has, the more CPU it will use; therefore you will start wasting CPU just because of this. With all that said, you need to unload MoH queues from tenants that are not being used on the given server.
Sadly, I can not give for free this script, as I consider this to be worthy of consulting services.
What happens after?
Good news! After I did that, my servers' CPU utilization went down. Some servers that they used to be almost a 50% CPU flat line, now they are rounding at 20%.
Enjoy the free stuff.
Good luck!blog comments powered by Disqus