Add a random, small time delay between update_tables.py cron jobs

Started by Marin BERNARD, July 06, 2020, 04:24:02 PM

Previous topic - Next topic
Hi,

So far, OPNsense regularly updates pf tables by running a Python script (/usr/local/opnsense/scripts/filter/update_tables.py) as a cron job on every minute. The invocation of the Python interpreter results in a substantial increase of CPU load for a few seconds.

When several OPNsense VMs are hosted on the same hypervisor, with properly configured time synchronization, the current schedule triggers the cron job at the very same time on every VM. This leads to CPU spikes every minute on the host system, as all VM compete for CPU time.

Would it be possible to add a small random delay at each cron job invocation to stagger table updates ? Something like:


/bin/sleep $(jot -r 1 1 45) && (/usr/local/bin/flock -n -E 0 -o /tmp/filter_update_tables.lock /usr/local/opnsense/scripts/filter/update_tables.py) > /dev/null


Many thanks,
--
Marin BERNARD
System administrator