Limiting Cron by Load Average
Is it possible with vixie cron to limit cron's activities by the current load average? Basically I'm looking for the same functionality that's in fcron, but I'm restricted to use the vixie cron with CentOS 5.3.
If not, does anyone have any recommendations on limiting the impact that cron has when it runs 20-30 user-specified crontabs at once?
Well Hetzner (a German hosting provider) uses something called "processwatch" to regulate crontabs (and all processes on their server). They don't seem to control the number of cron processes, but if something runs for too long (not sure how "too long" is defined...) it is killed automatically.
I mostly got around this by staggering my cronjobs, i. e.
Maybe you can also enforce staggering? Hetzner does this by limiting their web-interface for configuring your domain-wide cronjob by making it impossible to specify cronjobs "tighter" than once every ten minutes. They thus ensure that you won't be able to overload the server with cronjobs that run too quickly, one after the other.
(I have my own server with them, so I have SSH access, I manually wrote the above crontab, not through their interface - i. e. that is how I could run stuff each minute, not just every ten minutes as their KonsoleH web interface enforces).
Thanks for your reply and the information! I will look into something like processwatch and see if I can utilize it.
Staggering cron jobs does work and it works great. We had a server that was constantly hitting a load of 80 or higher and we couldn't figure out why. Finally we noticed that there were several hundred cron jobs running during the 5,10,30 minute intervals of the hour. I staggered all the jobs by 1-2 minutes and the load has not gone above 8 now.
So, it works great, but we have 40 servers to maintain and need to find a more universal solution. That's why I was looking into a queuing feature or I will even give processwatch a try and just kill the jobs.
I would love to move to fcron with it's queuing and load average support, but from what I read it is not 100% compatible with vixie cron (no cron.d support) and so I don't want to break our standard CentOS setup.
Ok well, glad to be of help.
Just a word about processwatch. I'm not sure (of course) what your setup or service level agreements with your customers / users are, but processwatch can be a nasty surprise to someone who might not be aware it is present. I. e. I never even -knew- it was running on Hetzner servers, until I one day scheduled a hugely important, reasonably "heavy" cronjob and it never completed - leaving a database halfway archived (in my own semantic view of the data) and causing chaos for some of my customers. I had a real storm of excrement to deal with when I got to the office that morning, and only THEN did I find out that processwatch was running on Hetzner servers, and I would NOT be able to execute the cronjob as planned.
I. e. just warn or publicize the fact (if you do use it or something like it) that you will be deploying this kind of load-limiting device for cronjobs, if you decide to do it, don't just quietly deploy it so it might catch some unwary developers - like it caught me!
may be this helps...
To prevent cron jobs from run during high system load I wrote some script. It checks the load and if it too high sleeps another period of time.
When loadavg become low it run its command-line.
For the cron I modified etc/crontab (F10 distro):
|All times are GMT -5. The time now is 12:46 AM.|