Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize daily/wwekly/monthly cronjob times #73

Open
bastelfreak opened this issue Feb 28, 2016 · 3 comments
Open

Randomize daily/wwekly/monthly cronjob times #73

bastelfreak opened this issue Feb 28, 2016 · 3 comments

Comments

@bastelfreak
Copy link
Member

An example Debian /etc/crontab:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 8    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 8    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 8    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

The hour in this example isn't randomized. If you install 50 virtual machines on one hypervisor, all VMs will run their crons at the same time. This will lead into IO issues. we need to:

  • Check which operating systems are affected by this (probably every that ships a cron daemon)
  • create a function to randomize the time for each installation between 1-24 o'clock.

We've already own a Debian specific function for randomizing the mdadm check time:

@dhxgit
Copy link
Member

dhxgit commented Feb 28, 2016

I think there are some implications here that users could depend on.
E.g.:
In all cases hourly jobs run before daily jobs, those run before weekly jobs and so on.
I also think that it is expected that those jobs run relatively early in the day, so the hour should be in the range of about 5 to 8.

For the minutes I would suggest to start with a random value from 0 to 19 for the minute of the hourly jobs, than add random 5 to 10 for daily, add random 5 to 10 for weekly, add random 5 to 10 for monthly.

@bastelfreak
Copy link
Member Author

I'm not sure about changing the minute at all because this adds a higher mount of complexity. what about running the jobs in the evening? between 10pm-8am for example? This should offer a range that is wide enough.

@bastelfreak
Copy link
Member Author

FYI example crontab from gentoo:

# check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
59  *  * * *    root    rm -f /var/spool/cron/lastrun/cron.hourly
9  3  * * *     root    rm -f /var/spool/cron/lastrun/cron.daily
19 4  * * 6     root    rm -f /var/spool/cron/lastrun/cron.weekly
29 5  1 * *     root    rm -f /var/spool/cron/lastrun/cron.monthly
*/10  *  * * *  root    test -x /usr/sbin/run-crons && /usr/sbin/run-crons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants