Cron jobs causing high CPU usage
I run several cron jobs on my server, about ten to fifteen in all, mostly all for backups.
I have staggered most of these so that the backups run mostly at night and have time to finish before the next one starts.
Recently, I noticed in Glances that I had a warning about a critical CPU alert. (Glances: a cross-platform monitoring tool that gives a comprehensive view of your system’s performance — https://blog.crowncloud.net/post/glances-overview-a-comprehensive-monitoring-tool-for-your-system/
Anyway, back to the story.
So I saw a CRITICAL CPU_TOTAL alert. Nothing serious, but I said to myself. I bet that some cron jobs arerunning at the same time together
And sure enough, I had two cron jobs that overlap around 3 PM
I have staggered most of these so that the backups run mostly at night and have time to finish before the next one starts.
Recently, I noticed in Glances that I had a warning about a critical CPU alert. (Glances: a cross-platform monitoring tool that gives a comprehensive view of your system’s performance — https://blog.crowncloud.net/post/glances-overview-a-comprehensive-monitoring-tool-for-your-system/
Anyway, back to the story.
So I saw a CRITICAL CPU_TOTAL alert. Nothing serious, but I said to myself. I bet that some cron jobs arerunning at the same time together
And sure enough, I had two cron jobs that overlap around 3 PM
- */5 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
- */10 * * * * /home/xxx/Documents/My_SH_files/ip_change_alert.sh
So at 3:00 PM, both run together, and after that:
- At 3:05 → only the Nextcloud cron runs.
- At 3:10 → both run together again.
- At 3:15 → only Nextcloud.
- At 3:20 → both again.
Basically, every 10 minutes (00, 10, 20, …, 50) they overlap on the hour and the first cron job can be CPU-consuming
Lowering the frequency
I don't really need these jobs to run so often, so at first I changed just the timings
*/20 * * * * /home/xxx/Documents/My_SH_files/ip_change_alert.sh
*/15 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
Better,butthey still run together on the hour, so once again I changed them to this
5-59/20 * * * * /home/xxx/Documents/My_SH_files/ip_change_alert.sh
*/15 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
So now I have:
👉 ip_change_alert.sh runs at :05, :25, :45.
Lowering the frequency
I don't really need these jobs to run so often, so at first I changed just the timings
*/20 * * * * /home/xxx/Documents/My_SH_files/ip_change_alert.sh
*/15 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
Better,butthey still run together on the hour, so once again I changed them to this
5-59/20 * * * * /home/xxx/Documents/My_SH_files/ip_change_alert.sh
*/15 * * * * docker exec -u www-data nextcloud php /var/www/html/cron.php
So now I have:
👉 ip_change_alert.sh runs at :05, :25, :45.
👉 Nextcloud cron runs at :00, :15, :30, :45
My backups still run at night, and I have no overlap with the frequent jobs
This should help my old Intel i7-4770 CPU @ 3.40GHz from over working,.
So nothing complicated, just staggering the cron jobs reduces my CPU from peaking and changes nothing for me.
My backups still run at night, and I have no overlap with the frequent jobs
This should help my old Intel i7-4770 CPU @ 3.40GHz from over working,.
So nothing complicated, just staggering the cron jobs reduces my CPU from peaking and changes nothing for me.