How to speed up the background tasks' execution using parallel cron processes

LiveAgent background tasks are executed by jobs.php started by cron. Even if you set cron to execute jobs.php every minute, the interval might still be too long for some operations (e.g. mass actions).

Fortunately, the background tasks are thread-safe and it is possible to run jobs.php in parallel by adding multiple cron entries. If however you just add the same entries multiple times to crontab, all the jobs.php processes would start at the same moment.

A better solution is to start 1 jobs.php process every 10 seconds instead of all at the same time every minute. To achieve this, you would configure the crontab like this:

* * * * * /usr/bin/php -q /var/www/liveagent/scripts/jobs.php  
* * * * * (sleep 10 ; /usr/bin/php -q /var/www/liveagent/scripts/jobs.php)
* * * * * (sleep 20 ; /usr/bin/php -q /var/www/liveagent/scripts/jobs.php)
* * * * * (sleep 30 ; /usr/bin/php -q /var/www/liveagent/scripts/jobs.php)
* * * * * (sleep 40 ; /usr/bin/php -q /var/www/liveagent/scripts/jobs.php)
* * * * * (sleep 50 ; /usr/bin/php -q /var/www/liveagent/scripts/jobs.php)

This will start all 6 processes at the same time, but process 2 to 6 will sleep for the configured number of seconds before executing jobs.php.

×