FreeSwitch: takes about 10 minutes to restart with 100% CPU

I installed freeswitch on openwrt-19 and on restart "top" shows this:

CPU:  99% usr   0% sys   0% nic   0% idle   0% io   0% irq   0% sirq
Load average: 0.15 0.12 0.33 2/41 1818
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 1807     1 freeswit R    10352  17%  99% /usr/bin/freeswitch -cache /tmp/freeswitch/cache -conf /etc/freeswitch -db /t

Eventually it starts though, about 10 minutes later, with only 30% CPU usage.

strace shows this:

strace: Process 1807 attached
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2735, tv_nsec=464294607}) = 0
getpid()                                = 1807
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2735, tv_nsec=514519305}) = 0
getpid()                                = 1807
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2736, tv_nsec=268770857}) = 0
getpid()                                = 1807
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2736, tv_nsec=318975704}) = 0
getpid()                                = 1807
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2737, tv_nsec=70847642}) = 0
getpid()                                = 1807
getpid()                                = 1807
clock_gettime(CLOCK_BOOTTIME, {tv_sec=2737, tv_nsec=121213175}) = 0
getpid()                                = 1807
...

I tried the same configuration on openwrt-18, and strace shows only getpid()

I've seen that, too. FS takes a while to restart. I think it may have something to do with it reading its database and reestablishing its state (for instance registrations, maybe even call state). That's just an idea, I never tried to find out what it is doing in detail as it never bothered me.

On my router this takes 15 to 30 seconds and afterward load goes down to ~ 2% when idle. I also found that it doesn't like when I try to connect with fs_cli before it settles. So I always wait until load goes down before doing anything else.

Mmh, maybe it's having a problems to sync to your clock? There's some info on this on the web, for instance here. The article also talks about ntp and the clock-related startup options. Maybe that can help you.

One thing I do for timekeeping with regards to FS is this. I install the ntpd package (make sure it's enabled in /etc/config/system). Then in /etc/config/freeswitch I enable hotplug for FS (by setting option interface to 'wan'), with option ntpd set to '1'. Finally I disable the FS autostart:

/etc/init.d/freeswitch disable

Like this FS isn't started automatically when the system boots. Instead it's started once the wan interface comes up, but only after the system clock is in sync with the ntp servers. This is also documented in the OpenWrt wiki article.

I don't know if it helps your situation, but it should be easy to try out, to see if has any benefit for your use case.