避免凌晨2点和3点的计划任务 (2013)
Avoid 2:00 and 3:00 am cron jobs (2013)

原始链接: https://www.endpointdev.com/blog/2013/04/avoid-200-and-300-am-cron-jobs/

## Cron 与夏令时:一个警示故事 避免在凌晨 2 点或 3 点安排 cron 任务,尤其是在星期天,以防止夏令时 (DST) 转换引起的问题。虽然 cron 任务通常运行良好,但每年两次,当 DST 开始或结束时,它们可能会在短时间内被重复触发(例如每秒一次!)。 这种“混乱”的重叠执行可能会使系统不堪重负,并用电子邮件淹没收件箱。虽然在某些情况下无害,但对于关键任务来说*可能*是灾难性的。 解决方案包括将服务器时区切换为 UTC(消除 DST 变化),或倡导彻底废除 DST。在更好的作业调度程序被广泛采用之前,最简单的解决方法是**避免使用 cron 安排这些特定时间**。这个简单的预防措施可以避免头痛和潜在的系统不稳定。

相关文章

原文

A word to the wise: Do not set any cron jobs for 2:00 am or 3:00 am on Sunday morning! Or to be safe, on other mornings besides Sunday as well, since jobs originally set to run on some particular day may eventually be changed to run on another day, or every day.

Most of the time such cron jobs will run fine, but if they run every Sunday morning, then twice per year they will run at the exact time daylight savings time (aka summer time) kicks in or ends, sometimes with very strange results.

On Linux with vixie-cron we saw two cron jobs run something like once per second between 3:00 and 3:01 when the most recent daylight savings time began. Thus they ran about 60 times, stepping all over each other and making a noisy mess in email. No serious harm was done, but that’s only because they were not tasks capable of causing serious harm.

Feel free to wish for or agitate for or fund or write a better open source job scheduler that everyone will use, one that will ensure no overlapping runs, allow specifying time limits, etc. Better tools exist, but until one of them achieves cron’s level of ubiquity, we have to live with cron at least some places and sometimes.

Alternatively, where possible set the server timezone to UTC so that no daylight savings changes will happen at all.

Or most preferable: Governments of the world, stop the twice-yearly dance of daylight saving time altogether.

But in the meantime this particular problem can be entirely avoided by just not scheduling any cron jobs to run on Sunday morning at 2:00 or 3:00 server time.

devops linux sysadmin


联系我们 contact @ memedata.com