Cron job setup, which way is better?

Hello,



I’m installing the cron job. I want to send email as often as possible, so I have to setup cron to run every minute. I have two options.


  1. Execute all commands at once every minute
Code:
*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1

With this method, the CPU went to the roof 100%, for about 3-5 seconds each time the cron run.
cach1.jpg

2. Make a batch script and make the previous command wait for 10 seconds before executing the next
Code:
*/1 * * * * /root/mtcron.sh > /dev/null 2>&1

The mtcron.sh file content:
Code:
#!/bin/bash php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1 sleep 10 php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1 sleep 10 php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1 sleep 10 php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1

With this method, the CPU never goes to the roof, but it will peak at around 60-70% for 4 times in a minute.
cach2.jpg

Which way is better?

Hello,

I’m installing the cron job. I want to send email as often as possible, so I have to setup cron to run every minute. I have two options.

  1. Execute all commands at once every minute

*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1 */1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1

With this method, the CPU went to the roof 100%, for about 3-5 seconds each time the cron run.

  1. Make a batch script and make the previous command wait for 10 seconds before executing the next
*/1 * * * * /root/mtcron.sh > /dev/null 2>&1

The mtcron.sh file content:

#!/bin/bash
php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1

With this method, the CPU never goes to the roof, but it will peak at around 60-70% for 4 times in a minute.

Which way is better?

I feel the second method is better as the CPU spikes and evenly distributed over a period of time as opposed to sharp spikes.

Please don’t trigger all actions at the same time. If you do, you will likely encounter this: https://github.com/mautic/mautic/issues/3669