| 232 | [[BR]] |
| 233 | |
| 234 | = Performance Tuning = #performance |
| 235 | |
| 236 | This section describes some performance tuning tips to reduce CPU utilization on the device. These are subset of the more [wiki:FAQ#cpu thorough performance tuning] as explained in the FAQ, please check that out for further reading. |
| 237 | |
| 238 | The recommendation below was based on experimentation on Z10 device. The full result of the experimentation is attached as PDF. The patch to measure CPU is also attached. |
| 239 | |
| 240 | === Tune Resampling Quality === |
| 241 | |
| 242 | Because default media clock rate is 16Khz (the {{{pjsua_media_config.clock_rate}}} setting), sample rate conversion (a.k.a resampling) will be used whenever a media port with clock rate other than 16Khz is added to the conference bridge. This happens, for example, when call is established with narrowband codec such as G.711, GSM, iLBC, Speex-NB, and AMR-NB. |
| 243 | |
| 244 | By default high quality resampling with large filter is used, and this uses a lot of CPU. The small filter resample produces indistinguishable result on mobile devices, and uses much less CPU. The small filter resample can be activated by setting {{{pjsua_media_config.quality}}} to 4 (default is 8), or by declaring {{{PJSUA_DEFAULT_CODEC_QUALITY}}} to 4 in {{{config_site.h}}}. This is now the default value in {{{config_site_sample.h}}}, so if your {{{config_site.h}}} includes {{{config_site_sample.h}}} (which is recommended above), you will get this setting. |
| 245 | |
| 246 | Changing {{{pjsua_media_config.quality}}} from 8 to 4 reduces CPU utilization for PCMU call from 13% to 3%. |
| 247 | |
| 248 | === Avoid Resampling Altogether === |
| 249 | |
| 250 | If all of your audio codecs are narrowband, then you should initialize PJSUA-LIB with 8Khz clock rate (set {{{pjsua_media_config.clock_rate}}} to 8000) to avoid resampling altogether. |
| 251 | |
| 252 | Without resampling, a PCMU call uses 0% CPU! |
| 253 | |
| 254 | === configure-bb10 script does not enable optimization by default === |
| 255 | |
| 256 | This applies to PJSIP's {{{configure-bb10}}} script and also the {{{generic-configure-bb10}}} for building OpenCore AMR-NB that is distributed by PJSIP-Demo. Both do not put "-O2" by default. |
| 257 | |
| 258 | Adding "-O2" could potentially reduce CPU utilization by 20%. |
| 259 | |
| 260 | === Codecs === |
| 261 | |
| 262 | Codec is the main contributor of CPU usage. Below is rough CPU utilization measurement for some codecs. Please see the attached PDF document for more complete results. |
| 263 | |
| 264 | Narrowband, without resampling (pjsua_media_config.clock_rate=8000): |
| 265 | - PCMU: 0% |
| 266 | - iLBC: 13% |
| 267 | - !OpenCore AMR-NB: 26% |
| 268 | |
| 269 | Narrowband, with small filter resampling (pjsua_media_config.clock_rate=16000, pjsua_media_config.quality=4): |
| 270 | - PCMU: 3% |
| 271 | - iLBC: 15% |
| 272 | - !OpenCore AMR-NB: 27% |
| 273 | |
| 274 | Wideband, without resampling (pjsua_media_config.clock_rate=16000): |
| 275 | - G.722: 5% |
| 276 | - !OpenCore Speex/WB: 20% |
| 277 | |
| 278 | |
| 279 | |
| 280 | |