简体   繁体   English

正确使用Cron工作的方法

[英]Proper Way to Use Cron Jobs

I am currently developing a website that has to perform a task every 10 seconds. 我目前正在开发一个网站,该网站必须每10秒执行一次任务。 The website checks a database every ten seconds, finds rows that are to be processed, and then run a short script on each row. 该网站每十秒钟检查一次数据库,查找要处理的行,然后在每一行上运行一个简短的脚本。

The service is working great right now, but I just want to make sure that once the database gets very large, the service will still work efficiently. 该服务现在运行良好,但是我只想确保一旦数据库变得很大,该服务仍将有效运行。

I am using a cron job that runs every minute, with sleep functions every 10 seconds. 我正在使用每分钟运行一次的cron作业,每10秒钟运行一次睡眠功能。

Thank you for your help! 谢谢您的帮助!

Just make sure your tasks don't overlap, ie wait till the previous task is over before launching a new one. 只要确保您的任务没有重叠,即等到上一个任务结束再启动新任务即可。 Otherwise, if your tasks take more than a minute (or whatever timer you've set for them), you'll end up with tons of those running in parallel and your system will run out of available resources. 否则,如果您的任务耗时超过一分钟(或您为其设置的任何计时器),最终将导致大量并行运行的任务,并且系统将耗尽可用资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM