It happens fairly frequently that user cron jobs on shared servers all run at the same time and get caught in contention (near as I've been able to tell). So load explodes, Nagios is angry, Apache stops responding, you can't SSH in because it times out, etc. I'm not in a position where I can just unilaterally decide users can't run crons, but I'd like to combat this issue where pgrep crond|wc -l returns >50.
It seems it should be possible to stagger them out by limiting the number of crond processes running at any given time or similar (like sending SIGSTOP until some of them clear up only less hacky), but I've yet to find any good leads.
The Hardware: 4 CPU and up, Low-end is Dell 1435s with ~8GB memory, RAID 10 WD EADS Mostly Plesk and cPanel, but also some evil Sphera systems.
How do you deal with this problem, sf?
You can use
cron.allow
andcron.deny
to limit user access to cron, or you can use PAM limits to limit CPU usage, number of processes and stuff like that. Aside from that, the solution is to create something to monitor and deal withcron
jobs by users, because cron don't really has a limit on how many jobs to run.I think CPanel has something on number of cron jobs running at the same time, but it's a specific tool (not sure).
I think you have one of those problems:
not enough memory to run the crontabs at the same time. You can fix by:
high I/O. You can fix by:
ionice
Try to find out if the machine is swapping, and if it is not swapping during the night, then change the cron I/O priority class to idle:
I have always scheduled cronjobs at random times (especially minutes). I commonly see cron examples that run at midnight like:
If you have a lot of jobs defined like that you are asking for trouble. Unfortunately these are often long running system jobs. I also tend to schedule jobs at different hours throughout a batch process window. (23 to 05) hours.
I like the new cron specification used on Ubuntu. This has several
/etc/cron.*
directories to specify jobs to run. They get run in sequence rather than parallel limiting the load.You should be able to see what is scheduled in the files located in
/etc/spool/cron/crontabs
. Reading these files will require root access. If it is users who are causing the problems discuss the problem with them.You could also check
/var/log/syslog
for CRON entries to see what is being run when.